Re:Side Effects vs. Promises
by saosebastiao on Sunday October 04, 2015 @12:31PM
(#10327957)
All of the back and forth on async callbacks vs async/await vs promises makes me sad that more people haven't yet discovered async computation expressions as found in F#. It is easily the most intuitive and expressive form of declarative async computation out there. I wish F# were more popular so it's revolutionary concepts like this one would bleed their way into other languages.
[ Parent
| on HN ]
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.
Re:Side Effects vs. Promises
by edgyswingset on Sunday October 04, 2015 @02:45PM
(#10328377)
I'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.
Async 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.
Re:Side Effects vs. Promises
by saosebastiao on Sunday October 04, 2015 @04:13PM
(#10328639)
It 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.
Re:Side Effects vs. Promises
by fennecfoxen on Sunday October 04, 2015 @01:39PM
(#10328142)
Pity that it's got the Microsoft cloud hanging over it, then (Mono notwithstanding)