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 SAA04173 for caml-redistribution; Mon, 22 Feb 1999 18:56:40 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA27464 for ; Mon, 22 Feb 1999 17:37:44 +0100 (MET) Received: from mail1.microsoft.com (mail1.microsoft.com [131.107.3.125]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id RAA12248 for ; Mon, 22 Feb 1999 17:37:40 +0100 (MET) Received: by mail1.microsoft.com with Internet Mail Service (5.5.2524.0) id ; Mon, 22 Feb 1999 08:37:39 -0800 Message-ID: <25983782061AD111B0800000F86310FE1026CB26@RED-MSG-42> From: Manuel Fahndrich To: caml-list@inria.fr Subject: RE: anonymous record types in variants Date: Mon, 22 Feb 1999 08:37:35 -0800 X-Mailer: Internet Mail Service (5.5.2524.0) Sender: weis I don't agree with Anton. The reason I want variants with anonymous record arguments is to name the fields explicitly. I don't want to incur a runtime cost of an extra indirection. The compilation of named fields vs. tuples would be the same. That's why a construction like > match x with A r -> ... r.x ... r.y ... would not be desirable, since it requires the record r to be stored as a separate block from the A r value. If you restrict record access for these anonymous records as Xavier pointed out > match x with A{lbl1 = x; lbl2 = y} -> ... then you can implement them as efficiently as a variant with a tuple argument. -Manuel -----Original Message----- From: Anton Moscal [mailto:msk@post.tepkom.ru] > It could be implemented this way. However, if you declare the > datatype as > > type foo = A of {lbl1 : int; lbl2 : int} > > you would be forced to pattern-match it as follows > > match x with A{lbl1 = x; lbl2 = y} -> ... > > but you can't get access to the record itself and use the dot notation > on it, as in > > match x with A r -> ... r.x ... r.y ... 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