From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q2OIXG2t025847 for ; Sat, 24 Mar 2012 19:33:16 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AosBAIwSbk9KfVI0kGdsb2JhbABEuBkIIgEBAQEJCQ0HFAQjggkBAQEEEgITGQEbHQEDDAYFCw0uIgERAQUBHAYTIodomxMKjBaCcYQrP4h2AQULkR0ElWCOTj2ECg X-IronPort-AV: E=Sophos;i="4.73,642,1325458800"; d="scan'208";a="137565422" Received: from mail-wg0-f52.google.com ([74.125.82.52]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Mar 2012 19:33:10 +0100 Received: by wgbgn7 with SMTP id gn7so3312806wgb.9 for ; Sat, 24 Mar 2012 11:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=dKiGT+8pPcRQG7xNk2Klc4ePCsd+jyYn8cUPaHI2lWw=; b=U9n/3ZxsJ/4L9s7wLG+EbzX4Pfz+4OYptwBkF3lbXs7STfc0+brcBRv62O+uq99vot JEhcxSxjN80F8CvNjIgbc72/GzIZhIY0cVDUdKvPhC1q5r/fcaMepm4bGByit+xLaedc WHLb0lYk6HLaCkyz0IHda96ayf2QJkiS7sl54BZXFKnGBzFntHzfkP+ka5UpbwWhBBtm YIVLoRQ6OwcVK2XnsUbQ/QEX4kgfpdb/+B9hsJbVfCViJ/4cZXpSd0fspQQSjlwKNHHQ tFFqH2HC2vLaytWO/29S3rrVGm9pdFyDQe87eeVaCa+N3x0zC0dYSoLL5v9reO/VkvQR 30iA== Received: by 10.180.79.72 with SMTP id h8mr6532840wix.1.1332613990256; Sat, 24 Mar 2012 11:33:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.180.19.97 with HTTP; Sat, 24 Mar 2012 11:32:48 -0700 (PDT) In-Reply-To: <87fwcx6ejm.fsf@frosties.localnet> References: <87fwcx6ejm.fsf@frosties.localnet> From: Lukasz Stafiniak Date: Sat, 24 Mar 2012 19:32:48 +0100 Message-ID: To: Goswin von Brederlow Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id q2OIXG2t025847 Subject: Re: [Caml-list] Wish: mutable variant types, equivalence with records On Sat, Mar 24, 2012 at 7:26 PM, Goswin von Brederlow wrote: > > So why not allow mutable in variant types and some equivalence with > records? For example: > > type = of [mutable] [:label] [| ...] > > as in: > > type foo = >  | Bar of int:i * mutable int:bar_used >  | Baz of float:f * mutable int:baz_used > > let use x = >  match x with >    | Bar bar -> >        bar.bar_used <- bar.bar_used + 1 >    | Baz baz -> >        baz.baz_used <- baz.baz_used + 1 > > let print x = >  use x; >  match x with >  | Bar bar -> Printf.printf "%d\n" bar.i >  | Baz baz -> Printf.printf "%f\n" baz.f > > The label is optional and any types in the constructor without label > would be translated into anonymous fields in a record that are > ineaccessible. > >  type foo = Foo of int * mutable int:used > > would be equivalent to { _ : int; mutable used : int; } > > Taking it one step wurther one could even allow: > > let bar = { i = 1; bar_used = 0; } > let foo = Bar bar > let foo = let Bar bar = foo in Bar { bar with i = 2; } > > > What do you think? I'm not sure about mutable but I'd appreciate labels :D