[Haskell-cafe] Flipping type constructors

Ryan Ingram ryani.spam at gmail.com
Mon Aug 20 23:33:56 CEST 2012


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 <tonymorris at gmail.com> wrote:

> 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/Control-Compose.html#Flip
>
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120820/30598c79/attachment.htm>


More information about the Haskell-Cafe mailing list