From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q2TMkdXi009933 for ; Fri, 30 Mar 2012 00:46:39 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlcDAODldE+K54gDgWdsb2JhbAAqEQm5GCIBARYmJ4IJAQEFJwsBBUARCxgJFg8JAwIBAgFFEwgCiAYLKbp1inSCdYMkBIhYjhqEX41D X-IronPort-AV: E=Sophos;i="4.75,339,1330902000"; d="scan'208";a="151862961" Received: from rouge.crans.org ([138.231.136.3]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 30 Mar 2012 00:46:33 +0200 Received: from localhost (localhost.crans.org [127.0.0.1]) by rouge.crans.org (Postfix) with ESMTP id 6482F85C6 for ; Fri, 30 Mar 2012 00:46:33 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at crans.org Received: from rouge.crans.org ([10.231.136.3]) by localhost (rouge.crans.org [10.231.136.3]) (amavisd-new, port 10024) with LMTP id GzWR6FBA3qBR for ; Fri, 30 Mar 2012 00:46:33 +0200 (CEST) Received: from [128.255.45.252] (dpmlh003.divms.uiowa.edu [128.255.45.252]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by rouge.crans.org (Postfix) with ESMTPSA id 05ADD85C1 for ; Fri, 30 Mar 2012 00:46:32 +0200 (CEST) Message-ID: <4F74E647.1040603@lri.fr> Date: Thu, 29 Mar 2012 17:46:31 -0500 From: =?ISO-8859-1?Q?Fran=E7ois_Bobot?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111114 Icedove/3.1.16 MIME-Version: 1.0 To: caml-list@inria.fr References: <87fwcx6ejm.fsf@frosties.localnet> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Validation-by: bobot@lri.fr Subject: Re: [Caml-list] Wish: mutable variant types, equivalence with records On 24/03/2012 13:45, Wojciech Meyer wrote: > Please see [1], Alain Frisch has been working recently on implementing > in-line records for constructor arguments. > > It's more implementation/design implications than people might think. > > [1] http://caml.inria.fr/mantis/view.php?id=5528 In the thread of this proposed feature, there is a remark that inlined record and normal record can become competing features. There is also the burden that inlined record as proposed can be modified only in pattern matching. But can't we consider that, for a semantic, syntax and typing perspective: type t = | A of string | B of ({msg: string; mutable foo:int} as t2) | C is exactly the same thing than: type t = | A of string | B of t2 | C and t2 = {msg: string; mutable foo:int} The only difference is that when you create a record of type t2 the tag is directly the one of B in the first case and is the default tag for record (the first tag if I remember well) in the second case. So in the first case applying the constructor B is just the identity. So you could modify the record of type t2 independently: val f : t2 -> t2 ... match x with | A s -> ... | B ({ msg = ""} as r) -> B (f t2) | C ... The only disadvantage, I see, compared to Alain Frisch's proposition is that two records share with difficulty the same field name. But special case can be made when we know the record type thanks to the constructor eg B {x=...}, C {x=...}. PS: It's in fact not the same thing for typing in regard of module subtyping, if t is made abstract, t2 must be made private. But that can be quite useful. -- François