[Haskell-cafe] Monad Transformer question

Fan Wu wufan9418 at gmail.com
Tue Nov 22 19:26:00 EST 2005

Hi Haskell gurus,

I'm learning Haskell now and here I'm quite puzzled over some code
about Monad Transformers. The code is like:

   type NDS a = StateT ProblemState [] a

   getVar :: Var -> NDS (Maybe Value)
   getVar v = do vs <- gets vars
                 return $ lookup v vs

What puzzles me is that, I think the Monad of the do block shall be
the "NDS (Maybe Value)" in declaration, but the type of gets is

    gets :: (MonadState s m) => (s -> a) -> m a

So "gets" returns a Monad of type m ([] is this case), which seems to
be different from "NDS (Maybe Value)", but GHC does not complain about

If I comment out the type declaration of "getVar :: Var -> NDS (Maybe
Value)" and let GHC interpret the type, then the type of getVar is

    getVar :: (MonadState ProblemState m) => Var -> m (Maybe Value)

So does it mean "StateT ProblemState m" and the "m" as in "MonadState
ProblemState m" is the same thing?

I guess I must missed something when trying to understand the Monad
Transformers. Please give me some insights.


More information about the Haskell-Cafe mailing list