
15 Apr
2015
15 Apr
'15
1:29 p.m.
On Wed, Apr 15, 2015 at 3:06 PM, silvio
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