[Hs-Generics] Generics and data families

Reiner Pope reiner.pope at gmail.com
Wed Mar 14 00:27:18 CET 2012


Hi all,

The DeriveGeneric language extension in ghc 7.4 does not support data families, so the following will not compile:

> data family D a
> data instance D Int = DInt  deriving Generic
> data instance D Bool = DBool  deriving Generic

On http://hackage.haskell.org/trac/ghc/ticket/5936, I provided a patch for ghc which makes the above compile, giving the (approximately) the following instances for Rep and Generic:

> type instance Rep (D Int) = D1 DIntInfo_D (C1 DIntInfo_C U1)
> type instance Rep (D Bool) = D1 DBoolInfo_D (C1 DBoolInfo_C U1)
>
> instance Generic (D Int) where ...
> instance Generic (D Bool) where ...

Note in particular that D Int and D Bool are considered completely distinct types as far as generics are concerned.

Is this the right approach to take to handle generics for data families? Are there alternative approaches? 

On the Trac ticket linked above, Pedro suggested we discuss these questions here.

Regards,
Reiner


More information about the Generics mailing list