It appears, as far as I can tell, that GHC can't move a forall past an
-> with coerce. I was playing around with the MonadTrans instance for
Codensity, wanting (essentially) to write
lift = coerce (>>=)
This is legal:
instance MonadTrans Codensity where
lift = frob
frob :: forall m a . Monad
Just to be clear, the Codensity bit (which I don't know) is a red herring here.
What you want is this:
> newtype A m a = MkA (forall b. m a -> (a -> m b) -> m b)
> newtype B (m :: * -> *) a = MkB (forall b. (a -> m b) -> m b)
>
> foo :: A m a -> (m a -> B m a)
> foo = coerce
On one level, this