[Haskell-cafe] Execution order in IO

Erik Hesselink hesselink at gmail.com
Wed Apr 15 13:29:28 UTC 2015


On Wed, Apr 15, 2015 at 3:06 PM, silvio <silvio.frischi at gmail.com> wrote:
> Now you can use that to implement your monads. For the state monad for
> instance there is a strict and a "lazy" version.
>
> newtype State s a = State { runState :: s -> (a,s) }
>
> instance Monad (State s) where
>     act1 >>= f2  = State $ \s1 -> runState (f2 input2) s2 where
>         (input2, s2) = runState act1 s1
>
> instance Monad (State s) where
>     act1 >>= f2  = State $ \s1 -> s2 `seq` runState (f2 input2) s2 where
>         (input2, s2) = runState act1 s1

Note that these do not correspond to the Strict and Lazy State in
transformers. The former (which you call lazy) corresponds to Strict
from transformers. The lazier version uses lazy pattern matching in
bind.

Erik


More information about the Haskell-Cafe mailing list