Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Ville-Pertti Keinonen <will@e...>
Subject: Re: [Caml-list] duplicate record labels and modules

On May 11, 2004, at 8:13 AM, briand@aracnet.com 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;

If you want to make it slightly less verbose, you can say

module F = Foo
module B = Bar

Or you could use "let module ... in".

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

> 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.

Nothing about "a" affects the meaning of the expression on the right 
hand side of the "=".

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

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners