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

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

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