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

Fan Wu wufan9418 at gmail.com
Thu Nov 24 13:24:30 EST 2005


Hi Wolfgang,

I don't know the history so maybe this is a new implementation of
State transformer. The Peek and poke functions are defined below
(copied from StateT.hs):

instance Monad m => StateM (StateT s m) s where
  peek              = S (\s -> return (s,s))
  poke s            = S (\s1 -> return (s1,s))

The question is why can't the mplus be written as simple as what
Andrew suggested:

    mplus m1 m2 = S (\s ->  let m1' = runState s m1
                               m2' = runState s m2
                           in  ~(a, s') <- mplus m1' m2'
                               return (a, s'))

this is easier to understand. I don't see what's the purpose of the
peek, lift, poke, return in the new implementattion.

Cheers,
Fan


More information about the Haskell-Cafe mailing list