News for hackers. Stuff that matters.
Re:Green vs. Brown Programming Languages by mrkeen on Thursday April 22, 2021 @05:19PM (#26908345)
> Initially they hadn’t even worked out how to do IO. I tried to find some date by which they'd figured it out, the best I can do is 1992[1].

To put it another way, Haskell's had a great story around IO for 29 years, or longer than Java's been around.

All the modern future/io/concurrency frameworks have followed suit. We construct objects representing computations and we flatMap them together, which is all the IO monad is. Although for some reason the syntax from last millennium hasn't made it into the modern languages:

    str1 <- readFile file1
    str2 <- readFile file2
    let str3 = str1 ++ str2
    writeFile file3 str3
vs:

    readFile(file1).flatMap(str1 -> {
        readFile(file2).flatMap(str2 -> {
            String str3 = str1 + str2;
            return writeFile(file3, str3);
    }});
[1] https://www.haskell.org/ghc/docs/papers/imperative.ps.gz
Re:Green vs. Brown Programming Languages by aranchelk on Thursday April 22, 2021 @11:52PM (#26910816)
> Haskell's had a great story around IO for 29 years, or longer than Java's been around.

I like that a lot. I did not realize that problem was solved so early on.

The things I was thinking of were more like good application frameworks, database libraries, etc. all the stuff you need to build commercial products and that you might have trouble justifying developing on an investor’s/shareholders’ dime.

Re:Green vs. Brown Programming Languages by astrange on Thursday April 22, 2021 @07:21PM (#26909313)
The popular syntax for this in newer imperative languages seems to be async/await, although I think I only like Swift's implementation. (unfair statement since I haven't used the rest much)
Re:Green vs. Brown Programming Languages by aranchelk on Friday April 23, 2021 @12:14AM (#26910923)
The cool thing about the syntax in Haskell is it’s not tied specifically to async, you can use it for synchronous IO, business logic, parsers, etc. It makes for small context switches when working on different parts of an application.
Re:Green vs. Brown Programming Languages by astrange on Friday April 23, 2021 @06:53PM (#26920191)
To adopt it in other languages don't you need non-strict evaluation, at which point it's hard to stop yourself from becoming Haskell?
Re:Green vs. Brown Programming Languages by aranchelk on Friday April 23, 2021 @10:38PM (#26921776)
Certain idioms in Haskell rely on laziness, but thankfully monads and do notation do not. They’re used in PureScript which is strict.
Re:Green vs. Brown Programming Languages by mavelikara on Saturday April 24, 2021 @04:22AM (#26923255)
> To put it another way, Haskell's had a great story around IO for 29 years, or longer than Java's been around.

That is a tall claim. LazyIO has been problematic in Haskell well into the 2010's until Iteratees became well-understood.

Re:Green vs. Brown Programming Languages by mavelikara on Saturday April 24, 2021 @05:29AM (#26923558)
Care to explain the downvote?

From Oleg Kiselyov's 2012 paper Iteratees [1]:

  Lazy IO is so irresistible that it was added to Haskell 
  despite the reservations of its inventors and the failure 
  to develop good techniques for reasoning about its correctness 
  [7, Sec 10.5]. However benign, reading is an observable 
  side-effect, whose occurrence may have to be correlated with 
  other side effects. Such correlations are crucial when 
  performing IO over communication pipes, which is typical of 
  web servers.3 As Launchbury and Peyton Jones feared, Lazy IO 
  indeed "gives rise to a very subtle class of programming errors". 
  We have seen deadlocks; mishandling of IO errors; running out of 
  file descriptors and similar scarce resources; unpredictable, 
  volatile and sometimes unbearably excessive use of memory. We 
  illustrate the splendors and miseries of Lazy IO in §2.
This is a very famous Haskell programer's opinion on the default IO in Haskell, and he quotes that one of the main creators of the language himself anticipated such problems [2]. Why downvote a comment in 2021 challenging the claim that "Haskell's had a great story around IO for 29 years"?

[1]: http://okmij.org/ftp/Haskell/Iteratee/describe.pdf

[2]: https://www.microsoft.com/en-us/research/wp-content/uploads/...

Re:Green vs. Brown Programming Languages by tome on Saturday April 24, 2021 @05:59AM (#26923703)
Iteratees (nowadays pipes, conduit etc.) are based on functionality that was already there in 1992. They didn't add anything to Haskell. They're just libraries. Lazy IO has indeed always been bad but it wasn't the only part of Haskell's IO story.
Re:Green vs. Brown Programming Languages by dllthomas on Tuesday April 27, 2021 @10:11PM (#26964644)
Lazy IO is great where lazy IO is great!

Long running processes handling lots of different requests, not so much, and that's made up an increasing amount of what people want to do.

But for "open a file, chew through it, errors when consuming it might as well take down the process" nothing could be easier.

Re:Green vs. Brown Programming Languages by mavelikara on Saturday April 24, 2021 @04:31PM (#26928061)
What were the other options available in Haskell in 1992, besides Lazy IO, which made for a great IO story then? Please point me to code or papers from then because I am genuinely interested to learn.
Re:Green vs. Brown Programming Languages by tome on Sunday April 25, 2021 @03:49AM (#26931059)
Reading and writing between handles and buffers, just like any other language. If you object specifically to the adjective "great" then, well, I don't think that was the operative point of the original comment.
Re:Green vs. Brown Programming Languages by mavelikara on Sunday April 25, 2021 @01:20PM (#26934474)
I object to both the use of “great” and the (needless, IMO) mention of Java in mrkeen’s comment.
Re:Green vs. Brown Programming Languages by mrkeen on Sunday April 25, 2021 @04:54AM (#26931317)
I might be naive, but I just assumed that I was still using lazy IO.

I've used conduits before, and understand that pipes fit the same design space.

But most of the time I just use read and write operations exposed by Bytestring, etc.

My point is that since I like IO today, and I didn't think that laziness had been removed, then I probably would have liked IO back in the day.

Re:Green vs. Brown Programming Languages by dllthomas on Tuesday April 27, 2021 @10:22PM (#26964723)
"Lazy IO" is things like `readFile :: FileName -> IO String`, where that String you get back secretly hides a thunk that will read more from the file when you evaluate it (even in pure code).

The operations provided by `Data.ByteString` do not work like this; the ByteString you get back represents a buffer, and it has already been processed by the time the RHS of >>= starts executing.

The operations provided by `Data.ByteString.Lazy`, on the other hand, do work like that; the ByteString you get back is a linked sequence of buffers, and some of those links might be thunks to go get the next bits of the ByteString for you.

This is why a Data.ByteString.ByteString and a Data.ByteString.Lazy.ByteString are different types, and you can't just pass one where the other is expected (unless you've abstracted over it) - they're actually shaped differently.