Records in Haskell

Johan Tibell johan.tibell at gmail.com
Sat Jan 14 19:38:53 CET 2012


On Fri, Jan 13, 2012 at 3:52 PM, Simon Peyton-Jones
<simonpj at microsoft.com> wrote:
> I know of no proposal that advocates only (A).  It seems that we are agreed
> that we must make use of types to disambiguate common cases.

I will try to make the case for (A), just so it has been put on the table.

Proposal
=========

The proposal is to implement
http://hackage.haskell.org/trac/ghc/wiki/Records/NameSpacing without
any of the type resolution parts. I think this approach is dismissed a
bit to easily on the wiki page above:

    "We have name-spaces, but it is hard to see how this is better
than the current practice of adding prefixes to record fields: data
Record = Record { recordA :: String }"

There are (at least) three benefits of using namespaces (e.g.
'Record.a') rather than ad-hoc prefixes (e.g. 'recordA'):

 * You can use a type synonym to abbreviate the namespace part (as
shown on the wiki page.)

 * If there's no ambiguity you don't need to use a namespace (e.g. you
can use 'a' instead of 'Record.a').

 * The namespace name is predictable (e.g. <Typename>.<fieldname>)
while ad-hoc prefixes tend to use different conventions e.g. the whole
record name (e.g. 'recordA') or some abbreviation thereof (e.g.
'rcrdA'.)

The main argument for this approach is its simplicity; it's simple to
understand for users and (hopefully) simple to implement.

Cheers,
Johan



More information about the Glasgow-haskell-users mailing list