Yeah, I notice many of the anonymous records systems papers talk about sum types but then never implement them. Section 2.1 Var
vs Rec
here, for example. I can see a few work-rounds, which make it probably not worth the complexity:
- Put the Variant as an ordinary ADT within a labelled field’s type:
{event = Key 'c'} :: {event :: Action Char}
vs{event = Mouse x y} :: {event :: Action Float}
. - Embed the record within a GADT:
Event {key = 'c'} :: Action (Rec {key :: Char})
vsEvent {mouse = (x, y)} :: Action (Rec {mouse :: (Float, Float)})
. - Use a different (set of) field label(s) for each variant:
{ key = 'c' }
vs{ mouse = (x, y) }
.
But yeah now you need heavyweight machinery. From a quick Google, purescript is aware of the value of GADTs, but they’re not there yet(?) They offer some work-rounds.
Variants by (set of) label(s) needs variant introduction/elimination type-level functions, sez section 6.1 at that link. But all we have is a typeclass/instance mechanism. I have built that in Hugs/Trex, more as an experiment to show how heavyweight it is than as a workable approach.