Changes between Initial Version and Version 2 of Ticket #27


Ignore:
Timestamp:
Jan 23, 2006 7:48:35 PM (10 years ago)
Author:
ijones
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27

    • Property Owner changed from ijones to simonpj@…
  • Ticket #27 – Description

    initial v2  
    11See ExistingRecords.  Create specific proposals for this.
     2
     3Here's a proposal from David Roundy (found on Haskell mailing list):
     4
     5I'd like to humbly submit a conservative proposal for changes to the
     6records mechanism for Haskell '06.  The plan for Haskell '06 (to the
     7extent
     8that there is one) is to make it a conservative modification of Haskell
     998, which is a good idea.  As such, I don't think features should be
     10added
     11to the language that haven't been both implemented and tested, and the
     12problem with the whole records problem is that pretty much every
     13proposed
     14improvement is *not* backwards-compatible with Haskell 98, and therefore
     15hasn't been either implemented or tried out.
     16
     17My idea is to make a small change, which will also not be
     18backwards-compatible with Haskell 98, but will *almost* be, and will be
     19hopefully forward-compatible with most complete solutions.  At a
     20minimum,
     21the proposed change will allow the prototyping of real solutions as a
     22non-invasive preprocessor a la DrIFT.
     23
     24My proposal is simply to remove the automatic declaration of accessor
     25functions.  In Haskell 98,
     26
     27{{{
     28data FooBar = Foo { foo :: Int } | FooBar = { foo :: Int, bar :: Int }
     29}}}
     30
     31desugars to something like
     32{{{
     33data FooBar = Foo Int | FooBar Int Int
     34
     35foo :: FooBar -> Int
     36foo (Foo f) = f
     37foo (FooBar f _) = f
     38bar :: FooBar -> Int
     39bar (Foo _) = error "bad Foo"
     40bar (FooBar _ b) = b
     41}}}
     42plus additional sugar for constructors and pattern matching.  I would
     43leave
     44the sugar for constructors and pattern matching in place, but remove the
     45automatic declaration of functions "foo" and "bar".
     46
     47This change "solves" the problem that different records in a single
     48namespace cannot share field names in a simple manner.  In order to
     49allow
     50the writing of records code with is both valid Haskell 98 and valid
     51Haskell
     52'06, I'd suggest a pragma that causes the Haskell '06 compiler to
     53generate
     54the accessor functions.  It's a bit ugly, but seems best to me.  An
     55alternative would be a standard TH function to do the same, but I don't
     56know if TH is going to be included in Haskell '06.
     57
     58This change may look like a step backwards (which it is), but I think
     59that
     60it would allow significant steps forward.
     61
     62
     63One open question (in my mind) would be whether we'd allow
     64{{{
     65data Foo = FooInt { foo :: Int } | FooChar { foo :: Char }
     66}}}
     67In the "new" system, there's no reason this need be illegal.