I use the genifunctors package to instantiate a functor for a type whose definition includes type families.
The first module defines the data type itself:
{-
This works as expected:
λ> import Temp λ> :t Baz $ Bar (Just "a") ["b"] Baz $ Bar (Just "a") ["b"] :: Baz [Char]
Functor instance is defined in a separate module:
{-
And gives this error:
λ> import Temp1 src/Temp2.hs:9:12-24: Exception when trying to run compile-time code: … unexpected TyCon: FamilyI (ClosedTypeFamilyD Temp.Fst [PlainTV p_1627394000] (Just StarT) [TySynEqn [AppT (ConT Temp.Record) (AppT (AppT (ConT GHC.Tuple.(,)) (VarT a_1627394001)) (VarT b_1627394002))] (VarT a_1627394001)]) [] Code: genFmap ''Baz In the splice: $(genFmap ''Baz)
This is because genifunctors , like geniplate , can only process types from newtype or data declarations.
This can be fixed by normalizing the type before recursively checking it.
So, is there a way to do this in a Haskell splice pattern? (I.e. in Q monad?)
haskell ghc template-haskell type-families data-kinds
vlopez
source share