Re: anonymous record types in variants

From: Christopher Jeris (
Date: Wed Feb 17 1999 - 19:09:06 MET

Date: Wed, 17 Feb 1999 13:09:06 -0500 (EST)
From: Christopher Jeris <>
To: Xavier Leroy <>,
Subject: Re: anonymous record types in variants
In-Reply-To: <>

On Wed, 17 Feb 1999, Xavier Leroy wrote:
> The reason why "{one : int}" is not a type expression but must be
> declared and bound to a type name have to do with type inference
> and the existence of principal types. If you allow record types in
> type expressions (as in SML), some functions have no principal type,
> such as fun x -> x.l.

But an analogous construction already exists in the object system:

# let f x = x#foo;;
val f : < foo : 'a; .. > -> 'a = <fun>

And indeed I can replace records by objects in my first example:

  type foo = One of < one : int > | Two of < two : string >

But this doesn't solve the problem since (I think) I now have to name the
object type in order to create objects which belong to it. So "open
record types" { one : int; .. } are just not a good idea ?

Another thing that kind of confuses me is open object types. Can the open
object type < one : int; .. > be defined directly in any way ?

  type foo = < one : int; .. >

is rejected since .. is unspecified. It seems that open object types can
result from inferences about the types of other objects/functions, but not
named directly ? (Or am I trying to do the wrong thing ?)

Sorry if these questions are kind of elementary. I'm still chewing on the
c/c0/c1/m example about 2/3 of the way through "Objects in Caml" :)

thanks & peace,

Chris Jeris MIT Math grad student & novice OCaml music programmer

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:19 MET