[Haskell-cafe] Execution order in IO
hyarion at iinet.net.au
Wed Apr 15 09:30:14 UTC 2015
It actually isn't written anywhere, and multiple statements in a do actually don't have to be evaluated in in the order they're written, for monads in general.
For most monads though, the implementation of >>= examines the left argument sufficiently to force things to be evaluated in that order (at least to the level of the monad's constructors).
IO in particular is implemented such that the effects of everything on the left of the bind (or earlier in a do block) will have been carried out before any of the effects from the right of the bind (later in the do). But even in the IO monad laziness can "delay" evaluation of pure computation mixed in with the IO actions; it just can't change the order the actions are executed in.
On 15 April 2015 7:07:24 pm AEST, Jon Schneider <haskell at jschneider.net> wrote:
>Good morning all,
>I think I've got the hang of the way state is carried and fancy
>work in monads but still have a major sticky issue.
>With lazy evaluation where is it written that if you write things with
>dependencies with a "do" things will be done in order ? Or isn't it ?
>Is it a feature of the language we're supposed to accept ?
>Is it something in the implementation of IO ?
>Is the do keyword more than just a syntactic sugar for a string of
>and lambdas ?
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe