Associativity of the generic representation of sum types
Bas van Dijk
v.dijk.bas at gmail.com
Thu Sep 22 19:31:39 CEST 2011
2011/9/22 Bas van Dijk <v.dijk.bas at gmail.com>:
> I just discovered the predicate:
> -- | Marks if this constructor is a record
> conIsRecord :: t c (f :: * -> *) a -> Bool
> I think this can solve my problem.
I think I have solved the bug now using conIsRecord. This is the new
However, I would still very much like to have the information, whether
a constructor is a record or not, statically available. This has two
* More efficient: programs can make a static instead of a dynamic choice.
* No more ugly undefined instances: because the information is not
statically available I need to add several "undefined" instances like:
instance GFromRecord (a :+: b) where gParseRecord = undefined
instance GFromRecord U1 where gParseRecord = undefined
instance GFromRecord (K1 i c) where gParseRecord = undefined
instance GFromRecord (M1 i c f) where gParseRecord = undefined
These instances will never be evaluated at runtime. They only exist to
satisfy the type-checker.
So I propose making the following changes to GHC.Generics:
Add a phantom type to C that specifies whether it's a record or not
using the (empty) datatypes:
Maybe it's also nice to have the type synonyms:
type R1 = M1 (C Record)
type P1 = M1 (C Product)
I will make an official ticket for this.
More information about the Glasgow-haskell-users