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

Wolfgang Jeltsch wolfgang at jeltsch.net
Thu Nov 24 05:46:36 EST 2005

Am Mittwoch, 23. November 2005 10:03 schrieb Fan Wu:
> Hi Haskell gurus,
> I'm very puzzled on some code I saw in GHC Monad.StateT (which is
> about state monad transformers) source and hope you can kindly give me
> some insight into this.
> newtype StateT s m a  = S (s -> m (a,s))
> instance MonadPlus m => MonadPlus (StateT s m) where
>   mzero             = lift mzero
>   mplus m1 m2       = do s <- peek
>                          let m1' = runState s m1
>                              m2' = runState s m2
>           ???????---->   ~(a,s') <- lift (mplus m1' m2')
>                          poke s'
>                          return a

Is this a new implementation of state transformers since I'ver never heard 
about peek and poke before (only get and put) and also thought that the 
argument order of runState was the other way round?  If yes, why did this new 
library retain this terrible naming of monad types?  Values of State don't 
denote states but state *transformers*.  I like to use significant variable 
names in my code and therefore I often use just the type name as a variable 
name.  So a value of type State would sometimes be named "state".  But what 
if I also have a variable that denotes a state?

> [...]

Best wishes,

More information about the Haskell-Cafe mailing list