Version française
Home     About     Download     Resources     Contact us    
Browse thread
Label Names Space - philosophy or implementation?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Gerard Malecki <johnm@v...>
Subject: Label Names Space - philosophy or implementation?

A co-worker has (vehemently) pointed out to me that record label names
cannot be shared.  For example, the following fails

	type foo = { name : string; x : int }
	let    a = { name = "foo";  x = 1 }

	type bar = { name : string; y : float }
	let    b = { name = "bar";  y = 9. }

	let   a' = { name = "foo";  x = 2 }

With an error message on the last line that "The label x belongs to
the type foo but is here mixed with labels of type bar".  This annoys
my co-worker to no end.  He would like many of his records to have a
field with a standardized label.  This makes it easier for him to
write printers for his data-structure.  Does anyone have a
recommendation to make to him?

Until this morning I would have guessed that the type of a record was
not resolved until all of the labels were examined.  As I re-read the
caml-light and ocaml manuals I see that this is not true.

Are there good reasons for this "restriction"?  I can see how this
this might be considered a good software practice.  Maybe, due to
pattern matching, it is not possible to have shared labels.

Any comments?