From: Pierre Weis <Pierre.Weis@inria.fr>
Message-Id: <199902221300.OAA07077@pauillac.inria.fr>
Subject: Re: anonymous record types in variants
To: msk@post.tepkom.ru (Anton Moscal)
Date: Mon, 22 Feb 1999 14:00:54 +0100 (MET)
In-Reply-To: <Pine.LNX.4.03.9902221137140.15888-100000@post.tepkom.ru> from "Anton Moscal" at Feb 22, 99 11:44:32 am
> But why? Natural semantic for anonymous types is the following: each
> anonymous record or algebraic types declaration introduces new type
> declaration in the current scope with some temporary type name. I.e.
>
> type ('a, 'b) foo = A of 'a * {l : 'b; l2: int}
>
> is a shortcut for:
>
> type ('a, 'b) temp_name = {l1 : 'b; l2: int}
> and ('a, 'b) foo = A of 'a * ('a, 'b) temp_name
>
> Regards,
> Anton Moscal
I proposed once (10 years ago ?) to have an ``as'' construct in data
type definitions: you could introduce a new datatype definition anywhere
in a datatype definition by writing
(type_definition_body as type_name)
with type_definition_body being one of the following:
[ | C1 {of t1} | C2 {of t2} | ...] for sum types
{ lab1 : t1; lab2 : t2; ... } for record types
type_expression for abbreviation types
the semantics you expect would then have been written as:
type ('a, 'b) foo = A of 'a * ({l : 'b; l2: int} as 'b temp_name)
This way the user could control the naming and number of type
arguments of the ``anonymous'' types defined, which is mandatory for
error messages from the typechecker, documentation purposes and clean
interfaces of modules.
As you mentioned it, such a scheme poses no problems at all to the
compiler, since it is just a shorthand for existing data type
definitions. On the other hand, it is conceivable to let the programmer
to expand this construct by hand, since it is just a few more lines to
write. That's the actual situation in the Caml light and Objective
Caml compilers.
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:20 MET