3 ms·
I haven't used F# much, but aren't computation-expressions just a Haskell like do-notation, which you get for free because the async type constructors are a mon
by Chattered 11y ago
I haven't used F# much, but aren't computation-expressions just a Haskell like do-notation, which you get for free because the async type constructors are a monad? Ocaml and Haskell should have this, at least, with lwt and its syntax extension, and Async respectively. I'm not sure what the situation is in Scala, but they surely have something similar with their generic for-comprehensions.
Outside of those, I don't know what the story is.
- edgyswingset 11y agoI'm not a Haskeller and haven't played with monads knowing they were monads, but async in F# basically works like this: 1. Call the function with async { } block and have it return a computation object 2. Start that computation object in three primary ways: a. On another thread, then wait (non-blocking) on it to finish b. On another thread but don't wait for it to finish c. On the current thread and don't wait for it to finish There's a lot more details but that's going to cover probably 95% of the use cases. My takeaways from it are: a. Super easy to write code for it that's easy to read b. Really hard to fuck it up In my opinion, it's superior to the model that C#/VB have ... and pretty much every other language I've tried async support on. Have yet to use Haskell for it.
- ufo 11y agoAsync is like having do-notation, but without having to convert your code to do-notation! Do-notation is nice but having a single notation for everything is even better. Both haskell and ocaml currently require you to use do-notation to write async code. I'm really looking forwards to algebraic effects landing in ocaml though because with that they will be introducing delimited one-shot continuations as part of the core language.
- saosebastiao 11y agoIt is very similar to do notation, but async expressions give you the ability to mix monadic and non-monadic code seamlessly and with uniform syntax within the same computation object. It's been a while since I've toyed with Haskell, but mixing regular Haskell and do-notation Haskell always felt like mixing two completely different languages.