(This is related to my previous post concerning monad transformers.)

GHC complains about:

> class (Monad m, {-, Monad (t m)-}) => MonadT t m where
>   lift :: m a -> (t m) a
>
> instance (Monad m) => Monad (EnvT env m) where
>   ...
>
> instance (Monad (EnvT env m)) => MonadT (EnvT env) m where
>   ...

saying that it cannot deduce (Monad m) to satisfy the second instance
declaration.  But it should be able to pick up that fact from the first
instance declaration, shouldn't it?

Indeed, if I add (Monad m) to the context explicitly:

> instance (Monad m, Monad (EnvT env m)) => MonadT (EnvT env) m where
>   ...

then GHC gives a warning when I import this module because the assumption
appears twice in a class context in the .hi file:

  Duplicated class assertion `Monad b' in the context:
    (Monad b, Monad Env.EnvT a b, Monad b)

Is this a bug, or am I confused?  In any case, why does GHC issue the
warning when I import the module instead of when I compile it?

--FC


Reply via email to