simple extension to ghc's record disambiguation rules

Anthony Clayden anthony_clayden at
Sat Feb 18 08:11:34 CET 2012

> Hi, I'd like to propose an extremely simple extension to
> ghc's record disambiguation rules,

John, I've just posted a proposal on the 'Records in
Haskell' wiki that I think will do the job for you.
"Declared Overloaded Record Fields" (DORF). I'd appreciate

> my motivation is that I often have record types with
> multiple constructors but common fields.

This is exactly the use case I'm aiming at.

> so, my proposal is that when you come across something
> like
> (e::RecType) { blah = foo }
> (with an explicit type signature like shown)
> ...

My proposal is the same, except that you don't need a type
sig (or not always).

That record syntax desugars to a call to `set', which is a
method of class `Has' (which also has method `get').

Has/get/set are overloaded for each record/field
combination. The instance is generated at the record
declaration, instead of the H98 record selector function.

> It is also backwards compatible for expressions, but would
> be a new thing for patterns which generally don't allow
> type signatures there.

DORF is backwards compatible with H98 record selectors, in
the sense that polymorphic selectors (using `get') are just

> It sidesteps type checker interactions by only being
> triggered when an explicit type annotation is included.

(DORF uses usual instance resolution by record type and

> ideally it would be combined with the 'update' and
> 'label-based pattern-matching' extensions from this page
>     John

DORF supports update and pattern matching by label, per
-XDismabiguateRecordFields and friends.


More information about the Glasgow-haskell-users mailing list