<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 24, 2016 at 11:22 AM, Kosyrev Serge <span dir="ltr"><<a href="mailto:_deepfire@feelingofgreen.ru" target="_blank">_deepfire@feelingofgreen.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Are you also saying that this cannot be resolved by some kind of a<br>
type families-based type-level 'flip'?<br>
<span class="im HOEnZb"></span></blockquote><div><br></div><div>It really can't, no. You can define<br><br></div><div>type family FlipF f a b where<br></div><div>  FlipF f a b = f b a<br><br></div><div>but FlipF, being a type family, is not first-class. You can't make any instances whatsoever for FlipF f a -- you'll probably get an error about a partially applied type family. What you *can* do is make a Flip newtype:<br><br></div><div>newtype Flip f a b = Flip {unflip :: f b a}<br><br></div><div>This behaves perfectly:<br><br></div><div>instance Bifunctor f => Functor (Flip f a) where<br></div><div>  fmap f = Flip . first f . unflip<br></div><div>instance Profunctor f => Contravariant (Flip f a) where<br></div><div>  contramap f = Flip . lmap f . unflip<br></div><div>instance Bifunctor f => Bifunctor (Flip f) where<br></div><div>  bimap f g (Flip x) = Flip (bimap g f x)<br></div></div></div></div>