Bitraversable is not derivable for These
Summary
I'm not sure whether this is technically a bug. But GeneralizedNewtypeDeriving
can't derive Bitraversable
for These
. Which is a pity, because it's nice to re-use all the instances for These
.
Steps to reproduce
$ cat Repro.hs
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Repro where
import Data.These
import Data.Bitraversable
import Data.Bifunctor
import Data.Bifoldable
newtype T a b = T (These a b) deriving (Bitraversable, Bifoldable, Bifunctor)
$ ghc Repro.hs
[1 of 1] Compiling Main ( Repro.hs, Repro.o )
Repro.hs:6:41: error:
• Couldn't match representation of type ‘f (These c d)’
with that of ‘f (T c d)’
arising from the coercion of the method ‘bitraverse’
from type ‘forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> These a b -> f (These c d)’
to type ‘forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> T a b -> f (T c d)’
NB: We cannot know what roles the parameters to ‘f’ have;
we must assume that the role is nominal
• When deriving the instance for (Bitraversable T)
|
6 | newtype T a b = T (These a b) deriving (Bitraversable, Bifoldable, Bifunctor)
| ^^^^^^^^^^^^^
$
Expected behavior
Bifoldable
and Bifunctor
both work, so I'd expect Bitraversable
to work too.
Environment
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.6.5