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