Re: anonymous record types in variants

From: Didier Remy (remy@morgon.inria.fr)
Date: Wed Feb 17 1999 - 20:14:03 MET


Date: Wed, 17 Feb 1999 20:14:03 +0100
From: Didier Remy <remy@morgon.inria.fr>
To: Christopher Jeris <cjeris@math.mit.edu>
Subject: Re: anonymous record types in variants
In-Reply-To: <Pine.SUN.4.03.9902171247250.28377-100000@severi.mit.edu>; from Christopher Jeris on Wed, Feb 17, 1999 at 01:09:06PM -0500

> But an analogous construction already exists in the object system:

I was expecting this question...

Yes, it is possible to have anonymous records and still keep principal
types, using `polymorphic' records (a restriction of `extensible records')
--this is the way objects are typed.

However, this will cost at runtime, unless there are very severe,
complicated compile-time/link-time optimizations. (In the case of objects,
this cost is expected because you are programming by message invocation.)

Since there are already objects in Ocaml, the need for
polymorphic/extensible records is not so strong. This would be convenient
but would not add much expressivity (you can always use objects). Hence the
gain may be insufficient to justify a complication of the language and of
the implementation.

> 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; .. >

Yes, but since this is a polymorphic type you have to write:

        type 'a foo = 'a constraint 'a = < one : int; ..>;;

This captures the polymorphic row variable `..' (that you are not allowed to
name directly) within the constrained type parameter 'a.

    Didier.



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