[Haskell] Re: (small) records proposal for Haskell '06

John Goerzen jgoerzen at complete.org
Wed Jan 4 09:17:27 EST 2006


On 2006-01-02, David Roundy <droundy at abridgegame.org> wrote:
> 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 }

I would find this to be incredibly annoying.  The fact that these
accessor functions exist automatically is, IMHO, one of the very nice
things about Haskell records.  I have nightmares of manually coding up
hundreds of get* and set* functions in Java from your proposal ;-)

I also would consider it a bug to have something so annoying that a
code-generation tool is required to work with it sanely.

Perhaps there is another approach.  In your example, perhaps we could
have:

class FooClass a where
    foo :: a -> Int

instance FooClass Foo where
   foo (Foo x) = x

instance FooClas FooBar where
   foo (FooBar x) = x

I don't know if compilers can do this automatically, but by importing
modules qualified, you can do this in Haskell today.

I believe this approximates the OCaml extension to solve the same
problem.

-- John



More information about the Haskell mailing list