From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA13770 for caml-redistribution; Mon, 22 Feb 1999 14:11:05 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA01223 for ; Mon, 22 Feb 1999 14:01:08 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id OAA15152; Mon, 22 Feb 1999 14:00:59 +0100 (MET) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA07077; Mon, 22 Feb 1999 14:00:54 +0100 (MET) From: Pierre Weis 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) Cc: caml-list@inria.fr In-Reply-To: from "Anton Moscal" at Feb 22, 99 11:44:32 am X-Mailer: ELM [version 2.4 PL24 ME8] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis > 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/