[Haskell-cafe] GHC 6.7 and Associated Types

Maxime Henrion mux at FreeBSD.org
Tue Apr 17 06:18:23 EDT 2007


	Hello guys,


I've been documenting myself on associated types, which look like a very
nice way to deal with the problems that arise with multi-parameter type
classes.  As an exercise, I am trying to rewrite the MonadState type
class from the mtl package without functional dependencies.

Here is my (probably very naive) approach :

class MonadState m where
  type StateType m :: *
  get              :: m StateType
  put              :: m StateType -> m ()

As for instances:

instance MonadState (State s) where
  type StateType = s                     -- this is line 22
  get            = State $ \s -> (s, s)
  put s          = State $ \_ -> ((), s)

I think I'm probably doing some very stupid thing and missing important
points.  In any case, here's the error I get :

State.hs:22:19: Not in scope: type variable `s'
Failed, modules loaded: none.

I'd be happy to be explained why this doesn't make sense, and how I
should proceed to implement this correctly.  I have tried various other
approaches with no luck yet.

Thanks,
Maxime


More information about the Haskell-Cafe mailing list