* [Caml-list] duplicate record labels and modules @ 2004-05-11 5:13 briand 2004-05-11 7:32 ` Ville-Pertti Keinonen 0 siblings, 1 reply; 5+ messages in thread From: briand @ 2004-05-11 5:13 UTC (permalink / raw) To: caml-list 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 :-) Thanks Brian ------------------- 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] duplicate record labels and modules 2004-05-11 5:13 [Caml-list] duplicate record labels and modules briand @ 2004-05-11 7:32 ` Ville-Pertti Keinonen 2004-05-11 16:10 ` briand 0 siblings, 1 reply; 5+ messages in thread From: Ville-Pertti Keinonen @ 2004-05-11 7:32 UTC (permalink / raw) To: briand; +Cc: caml-list 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] duplicate record labels and modules 2004-05-11 7:32 ` Ville-Pertti Keinonen @ 2004-05-11 16:10 ` briand 2004-05-11 17:46 ` brogoff 0 siblings, 1 reply; 5+ messages in thread From: briand @ 2004-05-11 16:10 UTC (permalink / raw) To: Ville-Pertti Keinonen; +Cc: caml-list >>>>> "Ville-Pertti" == Ville-Pertti Keinonen <will@exomi.com> writes: Ville-Pertti> 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; 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 closely. 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. Brian ------------------- 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] duplicate record labels and modules 2004-05-11 16:10 ` briand @ 2004-05-11 17:46 ` brogoff 2004-05-11 18:15 ` briand 0 siblings, 1 reply; 5+ messages in thread From: brogoff @ 2004-05-11 17:46 UTC (permalink / raw) To: briand; +Cc: caml-list On Tue, 11 May 2004 briand@aracnet.com wrote: > That's useful. I need to read the chapter on language extensions more > closely. Also, here's the requisite RTFM (I mean that F in the nicest possible way ;) http://caml.inria.fr/FAQ/FAQ_EXPERT-eng.html#labels_surcharge > 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 ? IMO, it's inconvenient, and a drawback to the language, but not a kludge, or even a mistake. I reserve that for the undefined order of evaluation :-). Oh well, you didn't expect paradise, did you? > I'm assuming the right way is to use modules, which is what started this > whole exercise for me. If you must share field names in the same module, your only alternative is to use the OO part of Ocaml. That's unfortunate, because I think objects are a bit heavyweight for things like points and segments in a computational geometry program. OTOH, Ocaml's object system is quite powerful and principled (and sometimes complex and unintuitive!) compared to lesser languages like C++ and Java. I often think a class system like CLOS or Dylan's would be more to my liking, but hard to reconcile with ststic typing and modules. -- Brian ------------------- 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] duplicate record labels and modules 2004-05-11 17:46 ` brogoff @ 2004-05-11 18:15 ` briand 0 siblings, 0 replies; 5+ messages in thread From: briand @ 2004-05-11 18:15 UTC (permalink / raw) To: brogoff; +Cc: caml-list >>>>> "brogoff" == brogoff <brogoff@speakeasy.net> writes: brogoff> On Tue, 11 May 2004 briand@aracnet.com wrote: >> That's useful. I need to read the chapter on language extensions >> more closely. brogoff> Also, here's the requisite RTFM (I mean that F in the brogoff> nicest possible way ;) brogoff> http://caml.inria.fr/FAQ/FAQ_EXPERT-eng.html#labels_surcharge I Just found it. It should have occurred to me that this subject would be an FAQ. However, my original question was more about the syntax of making using modules to separate the field name less typing-ful :-) 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 ? brogoff> IMO, it's inconvenient, and a drawback to the language, but brogoff> not a kludge, or even a mistake. I reserve that for the brogoff> undefined order of evaluation :-). Oh well, you didn't brogoff> expect paradise, did you? >> I'm assuming the right way is to use modules, which is what >> started this whole exercise for me. brogoff> If you must share field names in the same module, your only brogoff> alternative is to use the OO part of Ocaml. That's brogoff> unfortunate, because I think objects are a bit heavyweight brogoff> for things like points and segments in a computational brogoff> geometry program. OTOH, Ocaml's object system is quite brogoff> powerful and principled (and sometimes complex and brogoff> unintuitive!) compared to lesser languages like C++ and brogoff> Java. I often think a class system like CLOS or Dylan's brogoff> would be more to my liking, but hard to reconcile with brogoff> ststic typing and modules. I do _not_ need to use the same field name in the same module. So using modules is the right way and what I will do. For my current application objects are, as you say, too heavyweight. Brian ------------------- 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-05-11 18:15 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2004-05-11 5:13 [Caml-list] duplicate record labels and modules briand 2004-05-11 7:32 ` Ville-Pertti Keinonen 2004-05-11 16:10 ` briand 2004-05-11 17:46 ` brogoff 2004-05-11 18:15 ` briand
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox