Opened 13 years ago

Last modified 3 years ago

#27 new task

create proposal(s): tweak the existing records system

Reported by: ijones Owned by:
Priority: normal Milestone:
Version: Keywords:
Cc: Meta Owner:
State: Section: Declarations/Bindings
Related Tickets:

Description (last modified by ijones)

See ExistingRecords. Create specific proposals for this.

Here's a proposal from David Roundy (found on Haskell mailing list):

I'd like to humbly submit a conservative proposal for changes to the records mechanism for Haskell '06. The plan for Haskell '06 (to the extent that there is one) is to make it a conservative modification of Haskell 98, which is a good idea. As such, I don't think features should be added to the language that haven't been both implemented and tested, and the problem with the whole records problem is that pretty much every proposed improvement is *not* backwards-compatible with Haskell 98, and therefore hasn't been either implemented or tried out.

My idea is to make a small change, which will also not be backwards-compatible with Haskell 98, but will *almost* be, and will be hopefully forward-compatible with most complete solutions. At a minimum, the proposed change will allow the prototyping of real solutions as a non-invasive preprocessor a la DrIFT.

My proposal is simply to remove the automatic declaration of accessor functions. In Haskell 98,

data FooBar = Foo { foo :: Int } | FooBar = { foo :: Int, bar :: Int }

desugars to something like

data FooBar = Foo Int | FooBar Int Int

foo :: FooBar -> Int
foo (Foo f) = f
foo (FooBar f _) = f
bar :: FooBar -> Int
bar (Foo _) = error "bad Foo"
bar (FooBar _ b) = b

plus additional sugar for constructors and pattern matching. I would leave the sugar for constructors and pattern matching in place, but remove the automatic declaration of functions "foo" and "bar".

This change "solves" the problem that different records in a single namespace cannot share field names in a simple manner. In order to allow the writing of records code with is both valid Haskell 98 and valid Haskell '06, I'd suggest a pragma that causes the Haskell '06 compiler to generate the accessor functions. It's a bit ugly, but seems best to me. An alternative would be a standard TH function to do the same, but I don't know if TH is going to be included in Haskell '06.

This change may look like a step backwards (which it is), but I think that it would allow significant steps forward.

One open question (in my mind) would be whether we'd allow

data Foo = FooInt { foo :: Int } | FooChar { foo :: Char }

In the "new" system, there's no reason this need be illegal.

Change History (7)

comment:1 Changed 13 years ago by ijones

Owner: changed from ijones to simonpj@…

comment:2 Changed 13 years ago by ijones

Description: modified (diff)

comment:3 Changed 13 years ago by ijones@…

topic: Records & Data Types

comment:4 Changed 3 years ago by Herbert Valerio Riedel

Milestone:

moving non-milestoned many year old legacy tickets out of the way

comment:5 Changed 3 years ago by Herbert Valerio Riedel

Priority: majornormal

Set default priority (as this confuses Trac otherwise)

comment:6 Changed 3 years ago by Herbert Valerio Riedel

Owner: simonpj@… deleted

remove owners from legacy tickets

comment:7 Changed 3 years ago by David Luposchainsky

Section: Declarations/Bindings
Note: See TracTickets for help on using tickets.