[Haskell-cafe] Re: GHC 6.7 and Associated Types

apfelmus apfelmus at quantentunnel.de
Tue Apr 17 07:11:12 EDT 2007


Maxime Henrion wrote:
> 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

When defining the type function StateType, you have to give it the
required argument m = State s:

    type StateType (State s) = s

>   get            = State $ \s -> (s, s)
>   put s          = State $ \_ -> ((), s)

Regards,
apfelmus



More information about the Haskell-Cafe mailing list