
It seems really hard to solve this, since the type checker works before
instance selection has had a chance to do anything.
Instead of looking at the instance declaration, look at the use site:
lift x
expects the argument to have type
x :: t m a
for some t :: (* -> *) -> * -> *, m :: * -> *, and a :: *; it's not until t
is known that we can do instance selection, and in your case, EitherT M A B
doesn't have the required form and so is a type error already.
I think the best answer is sadly to just have to have a (kind-polymorphic!)
newtype flip and deal with it.
I can imagine there being some way to (ab)use kind polymorphism to redefine
MonadTrans in a way that allows the 'm' argument to appear in more places
in the target type, but I'm not clever enough to come up with a proposal
for how to do so.
-- ryan
On Mon, Aug 13, 2012 at 4:38 PM, Tony Morris
I have a data-type that is similar to EitherT, however, I have ordered the type variables like so:
data EitherT (f :: * -> *) (a :: *) (b :: *) = ...
This allows me to declare some desirable instances:
instance Functor f => Bifunctor (EitherT f) instance Foldable f => Bifoldable (EitherT f) instance Traversable f => Bitraversable (EitherT f)
However, I am unable to declare a MonadTrans instance:
instance MonadTrans (EitherT a) -- kind error
I looked at Control.Compose.Flip to resolve this, but it does not appear to be kind-polymorphic.
http://hackage.haskell.org/packages/archive/TypeCompose/0.9.1/doc/html/src/C...
I was wondering if there are any well-developed techniques to deal with this? Of course, I could just write my own Flip with the appropriate kinds and be done with it. Maybe there is a more suitable way?
-- Tony Morris http://tmorris.net/
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe