Changes between Initial Version and Version 2 of Ticket #27

Jan 23, 2006 7:48:35 PM (12 years ago)


  • Ticket #27

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

    initial v2  
    11See ExistingRecords.  Create specific proposals for this.
     3Here's a proposal from David Roundy (found on Haskell mailing list):
     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
     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
     11to the language that haven't been both implemented and tested, and the
     12problem with the whole records problem is that pretty much every
     14improvement is *not* backwards-compatible with Haskell 98, and therefore
     15hasn't been either implemented or tried out.
     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
     21the proposed change will allow the prototyping of real solutions as a
     22non-invasive preprocessor a la DrIFT.
     24My proposal is simply to remove the automatic declaration of accessor
     25functions.  In Haskell 98,
     28data FooBar = Foo { foo :: Int } | FooBar = { foo :: Int, bar :: Int }
     31desugars to something like
     33data FooBar = Foo Int | FooBar Int Int
     35foo :: FooBar -> Int
     36foo (Foo f) = f
     37foo (FooBar f _) = f
     38bar :: FooBar -> Int
     39bar (Foo _) = error "bad Foo"
     40bar (FooBar _ b) = b
     42plus additional sugar for constructors and pattern matching.  I would
     44the sugar for constructors and pattern matching in place, but remove the
     45automatic declaration of functions "foo" and "bar".
     47This change "solves" the problem that different records in a single
     48namespace cannot share field names in a simple manner.  In order to
     50the writing of records code with is both valid Haskell 98 and valid
     52'06, I'd suggest a pragma that causes the Haskell '06 compiler to
     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.
     58This change may look like a step backwards (which it is), but I think
     60it would allow significant steps forward.
     63One open question (in my mind) would be whether we'd allow
     65data Foo = FooInt { foo :: Int } | FooChar { foo :: Char }
     67In the "new" system, there's no reason this need be illegal.