Records (was Re: [Haskell] Improvements to GHC)

Wolfgang Jeltsch wolfgang at jeltsch.net
Mon Nov 28 13:41:14 EST 2005


Am Sonntag, 27. November 2005 22:34 schrieb John Lask:
> correct me if I am wrong but ...
>
> 1. Field namespaces: solved by using type classes
>
>     This would imply that the type of the field is the same between all
> instances of this common field.
>
>     Under this proposal two fields with same label and different type would
> not be possible
>     eg { name :: String }, { name :: Int }

As I already said, this approach may lead to mixing different concepts.  
Example:

	data Person = Person { name :: String }
	data File = File { name :: String }

A field identifier has to be seen in context of the datatype it belongs to.  
When used in conjunction with Person, name means a person's name while it 
means a filename (a notably different thing) when used in conjunction with 
File.  With the typeclass approach, we would have a single function called 
"name" which deals with different things.  Important details would just be 
camouflaged.  This is not good.  In fact, it is really bad in my opinion.

Maybe it would really be better to have functions like Person.name and 
File.name?

> John

Best wishes,
Wolfgang


More information about the Haskell mailing list