TypeFamilies vs. FunctionalDependencies & type-level recursion

Ben Millwood haskell at benmachine.co.uk
Wed Jun 15 14:58:58 CEST 2011


On Wed, Jun 15, 2011 at 11:36 AM, Simon Peyton-Jones
<simonpj at microsoft.com> wrote:
> |       instance (Monad m) => MonadState s (StateT s m) where
> |           get = StateT $ \s -> return (s, s)
> |
> |       instance (Monad (t m), MonadTrans t, MonadState s m) =>
> |              MonadState s (t m) where
> |               get = lift get
> |               put = lift . put
>
> Why do you need the first instance?  Isn't the second sufficient for (StateT s m) as well?
>
> Simon
>

The second will define /an/ instance for StateT s m, but it'll be the
wrong one :) the second instance says 'pass the responsibility for
dealing with state to the transformed monad', whereas the StateT wants
to deal with the state itself.



More information about the Haskell-prime mailing list