From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA27025; Sat, 24 Aug 2002 00:38:44 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 AAA27226 for ; Sat, 24 Aug 2002 00:38:43 +0200 (MET DST) Received: from mail3.tpgi.com.au (mail.tpgi.com.au [203.12.160.59]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7NMcfD22660 for ; Sat, 24 Aug 2002 00:38:41 +0200 (MET DST) Received: from ozemail.com.au (syd-ts15-2600-027.tpgi.com.au [203.213.83.27] (may be forged)) (authenticated (0 bits)) by mail3.tpgi.com.au (8.11.6/8.11.6) with ESMTP id g7NMaDi09935; Sat, 24 Aug 2002 08:36:14 +1000 Message-ID: <3D66B96A.9000505@ozemail.com.au> Date: Sat, 24 Aug 2002 08:38:34 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: nalexander@amavi.com CC: caml-list@inria.fr Subject: Re: [Caml-list] Naming polymorphic variant types References: <61954.209.139.221.124.1029974665.squirrel@mail.gx.ca> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Nick Alexander wrote: > Heh, that's what I thought. Oh well... maybe there is a way to do what I > want anyway. Let's say I have a record, say {a:int; b:int; c:int}. I > wish to have a function that returns sub-records, say {a:int; b:int} or > {b:int; c:int}. However, I don't want to (and can't, if I recall, due to > name clashes) declare all the sub record types. > I certainly don't understand enough type/category theory to > extend the system myself. > > Am I out of luck? AFAIK there's no reason it can't be implemented, but the result would not be compatible with the existing system. For example: type t = {a:int; b:int} let f x = x.a + 1 The type has to be assumed to be {>a:int} -> int (* #1 *) or {a:int} -> int (* #2 *) with polymorphic records (the declaration of type t is irrelevant). But the existing system deduces t -> int For polymorphic variants, a new syntax was used to get around the equivalent problem: that seems to be the main obstacle to me. The obvious candidate is: let f x = x.`a just like polymorphic variants. `a means polymorphic record label after a . or inside {} in leading position (after '{' or ';') It's not clear whether this style, with automatic conversions (#1): let f x = x.`a in ignore(f {`a=1}); ignore(f {`a=1; `b=2}) (* #1 *) would be better than requiring explicit conversion (* #2 *) .. f( {`a=1; `b=2) :> {`a:int} ) )(* #2 *) .. but clearly a physical conversion (actual run time operation) is required, so that the field is at the right offset. With polymorphic variants no physical conversion is required, it's a compile time typing thing only. [The typing in presence of mutable fields may complicate things] -- John Max Skaller, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners