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

it.

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

like:

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.

Thanks,

Fan

_______________________________________________

Haskell-Cafe mailing list

[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe