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: Alex Baretta <alex@b...>
Subject: [Caml-list] Records
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
variable.
Some record field labels are undefined <--- Why? rec1 defines
field1
# { field2 = 2 };; 
Some record field labels are undefined <--- Here I agree with the
interpreter
# { field1 = 1 ; field2 = 2 };;
- : rec2 = {field1=1; field2=2}      <--- Ok, so apparently he
likes records with 2 fields...

Now I try again, but this time I begin by defining a record with
two fields, and then I define a second one which shares one of
them.

# type var_def_rec = {name: string; value: int}
type var_decl_rec= {name: string}  ;;
type var_def_rec = { name : string; value : int; } 
type var_decl_rec = { name : string; } <--- Ok, so he accepted
them.
# { name = "alex" ; value = 1 };;
The record field label value belongs to the type var_def_rec
but is here mixed with labels of type var_decl_rec <--- Hein!
What?
# { name = "pippo" };;
- : var_decl_rec = {name="pippo"} <--- Now he seems to like
records with one field only!


WHY?

I cannot make any sense out of this. Please, help me.

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