[Haskell-cafe] How to implement this? A case for scoped record labels?

ntupel ntupel at googlemail.com
Thu May 28 01:45:17 EDT 2009

On Tue, 2009-05-26 at 18:09 -0400, wren ng thornton wrote:
> GADTs can easily cover record selectors that apply to all constructors, 
> and selectors that apply to one constructor (or a set of constructors 
> producing the same type). If the family of selector sets forms a nice 
> tree hierarchy, you can use phantom type constructors and type variables 
> to express subtrees of that hierarchy as types, e.g.
> I don't know if the Bayeaux protocol is amenable to this or not. And I'm 
> sure there's a prettier way to do it anyhow.
> By using multiple phantom types you can encode any subset relation on 
> selector sets that can be described by a tree-ordered space. If the 
> subset relation is DAGy, then things get ugly again. You'll probably 
> have to use typeclasses in some form or another eventually, the question 
> is how much you rely on ad-hoc overloading vs how structured you can 
> make things by using other techniques.

Finally I got your point. Many thanks for your explanation. So, yes, in
principle GADTs seem helpful here, but it turned out that for Bayeux the
relations are difficult to encode and it seems I would indeed at least
partially have to use type classes again. It really is fascinating, I
learned a lot in the last days about GADTs, type families, and other
type trickery. Never mind that I still struggle to see an obvious
implementation strategy, all proposed solutions look like workarounds to
the lack of scoped record labels to me. Maybe I should just use prefixes
for the record selectors of individual data types. D'oh!


More information about the Haskell-Cafe mailing list