simple extension to ghc's record disambiguation rules

John Meacham john at repetae.net
Sat Feb 18 03:01:23 CET 2012


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

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

so the handy idiom of

f Rec { .. } = do
        blah
        return Rec { .. }

won't work, because I don't know the specific constructor.

so, my proposal is that when you come across something like

(e::RecType) { blah = foo }

(with an explicit type signature like shown)

You interpret 'blah' as if it is a field of the record of type 'Rec'. This
gives the advantages of record field names being scoped by type but without
you having to specify the precise constructor.

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

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

ideally it would be combined with the 'update' and 'label-based
pattern-matching' extensions from this page
http://hackage.haskell.org/trac/haskell-prime/wiki/ExistingRecords

    John



More information about the Haskell-prime mailing list