Discussion:
[Hs-Generics] Generics and data families
Reiner Pope
2012-03-13 23:27:18 UTC
Permalink
Hi all,
data family D a
data instance D Int = DInt deriving Generic
data instance D Bool = DBool deriving 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
Reiner Pope
2012-03-13 23:30:15 UTC
Permalink
Hi all,

I am of the opinion that the approach I described in my previous email is reasonable. To me, the key point is that the Generic class (as opposed to the Generic1 class) is for types of kind *. Since D Bool and D Int are different types of kind *, it is reasonable for them to have unrelated instances for Generic. (The situation would be different for Generic1, once GHC supports deriving that).
{-# LANGUAGE DeriveGeneric, FlexibleInstances, StandaloneDeriving #-}
import GHC.Generics
data T a = T a
deriving instance Generic (T Bool)
instance Generic (T Bool) where ...
type instance Rep (T a) = ...
{-# LANGUAGE DeriveGeneric, FlexibleInstances, StandaloneDeriving #-}
import GHC.Generics
data T a = T a
deriving instance Generic (T Bool)
deriving instance Generic (T Int)
because the "type instance Rep (T a) = ..." declarations conflict.
instance Generic (T Bool) where ...
type instance Rep (T Bool) = ...
Note that these instances are of exactly the same form as the data family instances of my previous email.

Regards,
Reiner
Hi all,
data family D a
data instance D Int = DInt deriving Generic
data instance D Bool = DBool deriving 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
José Pedro Magalhães
2012-03-14 07:40:20 UTC
Permalink
Hi Reiner,
{-# LANGUAGE DeriveGeneric, FlexibleInstances, StandaloneDeriving #-}
import GHC.Generics
data T a = T a
deriving instance Generic (T Bool)
instance Generic (T Bool) where ...
type instance Rep (T a) = ...
Oh, this is a bug. I'll open a ticket for it and fix it soon.


Thanks,
Pedro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/generics/attachments/20120314/c50f2e70/attachment.htm>
Loading...