It turns out that Data.Bifunctor.TH suffers from the same bug that caused GHC#17880. Here is a minimal demonstration of the bug:
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
module Bug where
import Data.Bifunctor.TH
data T a b = MkT (forall c. c -> (forall d. a -> d) -> a)
$(deriveBifunctor ''T)
This should compile, but fails with the following error:
```
Bug.hs:8:3: error:
• Couldn't match type ‘forall d1. a -> d1’ with ‘a -> p0’
Expected type: c1 -> (a -> p0) -> a
Actual type: c1 -> (forall d. a -> d) -> a
• In the first argument of ‘\ x_ajqV b_ajqW
-> (\ x_ajqX b_ajqY
-> f_ajqR
(x_ajqX
((\ x_ajqZ b_ajr0
-> (\ x_ajr1 -> x_ajr1)
(x_ajqZ (f_ajqR b_ajr0)))
b_ajqY)))
(x_ajqV ((\ x_ajr2 -> x_ajr2) b_ajqW))’, namely
‘_arg1_ajqU’
In the first argument of ‘MkT’, namely
‘((\ x_ajqV b_ajqW
-> (\ x_ajqX b_ajqY
-> f_ajqR
(x_ajqX
((\ x_ajqZ b_ajr0 -> (\ x_ajr1 -> x_ajr1) (x_ajqZ (f_ajqR b_ajr0)))
b_ajqY)))
(x_ajqV ((\ x_ajr2 -> x_ajr2) b_ajqW)))
_arg1_ajqU)’
In the expression:
MkT
((\ x_ajqV b_ajqW
-> (\ x_ajqX b_ajqY
-> f_ajqR
(x_ajqX
((\ x_ajqZ b_ajr0 -> (\ x_ajr1 -> x_ajr1) (x_ajqZ (f_ajqR b_ajr0)))
b_ajqY)))
(x_ajqV ((\ x_ajr2 -> x_ajr2) b_ajqW)))
_arg1_ajqU)
• Relevant bindings include
_arg1_ajqU :: forall c. c -> (forall d. a -> d) -> a
(bound at Bug.hs:8:3)
value_ajqT :: T a c (bound at Bug.hs:8:3)
f_ajqR :: a -> b (bound at Bug.hs:8:3)
bimap :: (a -> b) -> (c -> d) -> T a c -> T b d
(bound at Bug.hs:8:3)
|
8 | $(deriveBifunctor ''T)
| ^^^^^^^^^^^^^^^^^^^
```
GHC has fixed this bug upstream, and it should be possible to apply a similar fix in Data.Bifunctor.TH.
It turns out that
Data.Bifunctor.TH
suffers from the same bug that caused GHC#17880. Here is a minimal demonstration of the bug:This should compile, but fails with the following error:
GHC has fixed this bug upstream, and it should be possible to apply a similar fix in
Data.Bifunctor.TH
.