3 ms·
That's exactly what monadic code in Haskell does --- a Haskell `do` block sets up a callback chain, and then when the runtime evaluates the chain, all the entri
by david-given 10y ago
That's exactly what monadic code in Haskell does --- a Haskell `do` block sets up a callback chain, and then when the runtime evaluates the chain, all the entries in the chain happen in the right order. Dependencies between items in the chain and between different chains happen automagically.
Because all mutable state is encapsulated inside the monad and only actually takes effect when the state changes get applied to the outside world, it also allows really cool things like abandoning and retrying state changes if the state's not right. This allows really cool things like STM's 'atomically' operation. Behind the scenes it'll roll back and retry the operation whenever necessary --- but you never need to care: the effect of the operation gets applied to the outside world exactly once.