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

David Roundy droundy at abridgegame.org
Thu Jan 5 09:23:50 EST 2006


On Wed, Jan 04, 2006 at 03:03:40PM -0800, John Meacham wrote:
> On Wed, Jan 04, 2006 at 08:55:39AM -0500, David Roundy wrote:
> > Ah, good point, I hadn't thought about that.  My proposal was to keep
> > record updates which would indeed mean that we'd need to require that all
> > "foo"s in a given data type have the same type.  Which I don't think is a
> > bad thing either... it just hadn't occurred to me.
> 
> The issue is with multiple data types that have the same field name, not
> the same field reused within a data type. for instance
> 
> 
> data Foo = Foo { foo :: Int }
> data Bar = Bar { foo :: Int }
> 
> f x = x { foo = 4 }
> 
> what type does f have?
> 
> f :: Foo -> Foo
> or
> f :: Bar -> Bar
> ?

Ah yes, that would seem to be a problem.  The only solution I can imagine
would be to implement a class for each field name.  i.e. the only reasonble
type of f I can imagine is something like

f :: Integral i, RecordHasField_foo i r => r -> r

But that's a very complicated solution, and once one implemented that
solution, one would no longer need to remove the accessor functions (since
they could be stuck in the class), which would obsolete this whole idea...
:(
-- 
David Roundy
http://www.darcs.net


More information about the Haskell mailing list