Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] duplicate record labels and modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-05-11 (16:11)
From: briand@a...
Subject: Re: [Caml-list] duplicate record labels and modules
>>>>> "Ville-Pertti" == Ville-Pertti Keinonen <> writes:

  Ville-Pertti> On May 11, 2004, at 8:13 AM, wrote:

  >> Consider the following :
  >> let a = {Foo.n1=1; Foo.n2=2; Foo.a=(- 1.0)} in
  >> let b = {Bar.n1=4; Bar.n2=(- 5); Bar.b=77.} in
  >> Printf.printf "%d\n" a.Foo.n1;
  >> Printf.printf "%d\n" b.Bar.n1;

  Ville-Pertti> If you want to make it slightly less verbose, you can say

  Ville-Pertti> module F = Foo
  Ville-Pertti> module B = Bar

  Ville-Pertti> Or you could use "let module ... in".

That's useful.  I need to read the chapter on language extensions more

  Ville-Pertti> Alternately, assuming the modules are your own, you
  Ville-Pertti> can name your record fields so that opening both
  Ville-Pertti> modules doesn't cause conflicts (e.g. using a short
  Ville-Pertti> prefix).

That's very kludgy, isn't it ?  I'm assuming the right way is to use
modules, which is what started this whole exercise for me.

  >> let (a:Foo.t) =  {n1=1; n2=2; a=(- 1.0)} in
  >> Unbound record field label n1
  >> After careful review of the grammar I discovered that is incorrect,
  >> although it seems like it should work.

  Ville-Pertti> Nothing about "a" affects the meaning of the
  Ville-Pertti> expression on the right hand side of the "=".

  Ville-Pertti> Even if it did, the visibility of identifiers is
  Ville-Pertti> determined only by lexical scope, typing has no
  Ville-Pertti> effect, which is why even if you have "a:Foo.t" in
  Ville-Pertti> scope, you can't access "a.n1".

Oh yes.  That makes makes sense.

Thanks for your help.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: