Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Records with same structure in OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Rogoff <bpr@b...>
Subject: Re: [Caml-list] Records with same structure in OCaml
On Sat, 6 Apr 2002, Oliver Bandel wrote:
> Hello,
>
>
> when I use two records with the same structure,
> how can they be distinguished? And how can
> the correct type be choosed?

This question comes up frequently enough to be a FAQ entry

http://caml.inria.fr/FAQ/FAQ_EXPERT-eng.html#labels_surcharge

and the most frequent answer is "Don't do that!", meaning either
disambiguate the field names if the records are defined in the same module

type complex = { complex_re: float; complex_im: float };
type foo     = { foo_re: float; foo_im: float };

or put each definition in its own module and use the fully qualified name
if you must mix them. You can also use classes, but if you're a
performance junkie you should realize that you give up a lot of
performance, especially in the example you use, complex numbers. You also
lose pattern matching (and gain some polymorphism) is you use the class
system.

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