English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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 (05:13)
From: briand@a...
Subject: [Caml-list] duplicate record labels and modules

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;

That's too verbose, and I can't use open or I get the dreaded mixing
labels problem.  So how about:

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.

A little more perusing and I found:

let-binding ::= pattern = expr 
                | value-name { parameter } [: typexpr] = expr

and that makes sense.  I'm simply explictly annotating the type of a,
right ?

So I tried:

let a:Foo.t =  {n1=1; n2=2; a=(- 1.0)} in

And got the same error, i.e. unbound field n1....

I'm doing a lot of work so I can be lazy :-)



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