Records in Haskell

Isaac Dupree ml at
Thu Mar 1 05:18:54 CET 2012

On 02/28/2012 06:40 AM, AntC wrote:
> Oliver Batchelor<saulzar<at>>  writes:
>> Perhaps this situation could occur though?
>> Module A
>> fieldLabel name String
>> Module B
>> import A -- unknowingly picking up the name label
>> data Foo = Foo { name :: String } -- uses the name label by accident
>> So there'd have to be some syntax to make sure you intend to use a
>> label rather than accidentally use it?
>> (Not that this is a big issue, the situation is surely minor compared
>> to sharing unrelated labels all the time)
>> Oliver
> Thanks Oliver, hmm ...

Oliver's example is exactly what I feel weird about (and what I refered 
to as a "magical effect").  Sorry for failing to communicate to you 

In the meantime, I had an idea (that could work with SORF or DORF) :

data Foo = Foo { name :: String } deriving (SharedFields)

The effect is: without that "deriving", the declaration behaves just 
like H98.

(For super flexibility, allow to specify which fields are shared,
like "deriving(SharedFields(name, etc, etc))" perhaps.)

Is it too verbose? Or too terrible that it isn't a real class (well, 
there's Has...)?


More information about the Glasgow-haskell-users mailing list