[Haskell-cafe] questions on lazy pattern, StateT monad

Fan Wu wufan9418 at gmail.com
Wed Nov 23 19:49:12 EST 2005

Hi Wolfgang,

Thanks for your response and examples! It helps a lot.

>From your example I can see "Lazy patterns are useful in contexts
where infinite data structures are being defined recursively" (quote
section 4.4 of Gentle Introduction to Haskell). But does it apply to
the mplus case? I mean the mplus in (mplus m1 m2) and the mplus in
(mplus m1' m2') are different due to the difference of Monads (one is
StateT s m, the other is just m). If I change the mplus inside lift to
something else like:

  mplus m1 m2       = do s <- peek
                         let m1' = runState s m1
                             m2' = runState s m2
                         ~(a,s') <- lift (other_func m1' m2')
                         poke s'
                         return a

Is it still required that (a,s') be lazy?

I just want to see how things works in an less obvious example like this one.


More information about the Haskell-Cafe mailing list