caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Records
@ 2001-03-22 12:34 Alex Baretta
  2001-03-22 13:10 ` Sven LUTHER
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Baretta @ 2001-03-22 12:34 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Records
  2001-03-22 12:34 [Caml-list] Records Alex Baretta
@ 2001-03-22 13:10 ` Sven LUTHER
  0 siblings, 0 replies; 2+ messages in thread
From: Sven LUTHER @ 2001-03-22 13:10 UTC (permalink / raw)
  To: Alex Baretta; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-03-22 13:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-22 12:34 [Caml-list] Records Alex Baretta
2001-03-22 13:10 ` Sven LUTHER

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).