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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sven LUTHER <luther@d...>
Subject: Re: [Caml-list] Records
On Thu, Mar 22, 2001 at 01:34:04PM +0100, Alex Baretta wrote:
> Basically I'm trying to define two record type as sharing some
> field names. I have tried twice, apparently in the same way, and
> obtained two different error messages, which seem to contradict
> one another. Could anyone explain to me what is happening here?
> 
> 
>         Objective Caml version 3.00
> 
> # type rec1 = { field1 : int }
>   type rec2 = { field1 : int ; field2 : int };; <--- Here I define
> my two record types
> type rec1 = { field1 : int; } 
> type rec2 = { field1 : int; field2 : int; } 
> # { field1 = 1 };; <--- This is supposed to be a correct rec1

no, it is a rec2 record, since field1 was lastly defined for rec2.

One workaround would be :

module Rec1 = struct
  type t = {field1 : int}
end
module Rec2 = struct
  type t = { field1 : int; field2 : int; } 
end

Then you can do :

{Rec1.field1 = 1} : Rec1.t

or 

{Rec2.field1 = 1; Rec2.field2 = 2} : Rec2.t

If you are interrestedin more such things, i remember a discution about such
things some time ago on this list, please look at the mailing list archive for
more details.

Friendly,

Sven Luther
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr