Browse thread
anonymous record types in variants
-
Christopher Jeris
- Anton Moscal
-
Xavier Leroy
- Christopher Jeris
- Anton Moscal
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Christopher Jeris <cjeris@m...> |
| Subject: | Re: anonymous record types in variants |
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