[Haskell-cafe] Swapping type arguments

MigMit miguelimo38 at yandex.ru
Fri May 1 19:36:23 UTC 2015


There is none. No type can be an instance of both classes, as their signatures are too different.

You can create your own type class instead of MonadTrans (or Bifunctor), or you can wrap T in a newtype, swapping arguments.

> On 01 May 2015, at 21:32, Alexey Uimanov <s9gf4ult at gmail.com> wrote:
> 
> This question probably asked already. 
> 
> I have a type 
> 
> data T m b a = T (m (b, a))
> 
> and it should be instance of `Bifunctor` and `MonadTrans` same time. But there is a problem: 
> 
> instance Bifunctor (T m) 
> 
> is ok, but 
> 
> instance MonadTrans (T ...
> 
> is not, because first argument is `m` but we need `b`. Type can be rewritten like 
> 
> data T b m a = T (m (b, a))
> 
> and instance of MonadTrans is ok: 
> 
> instance MonadTrans (T b)
> 
> but how to define Bifunctor? 
> 
> instance Bifunctor (T ...
> 
> I did not found how to workaround this. Is there any type magic for such cases?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list