From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 440467EE4C for ; Thu, 10 Oct 2013 21:42:04 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of dra-news@metastack.com) identity=pra; client-ip=62.13.128.67; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="dra-news@metastack.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of dra-news@metastack.com designates 62.13.128.67 as permitted sender) identity=mailfrom; client-ip=62.13.128.67; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="dra-news@metastack.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@outmail128067.authsmtp.com) identity=helo; client-ip=62.13.128.67; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="postmaster@outmail128067.authsmtp.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgcBAOgBV1I+DYBDl2dsb2JhbABZgmaBK8EvgSUWDgEBAQEBCBYHPIIlAQEBAwEnE0QLAgEIGAoUEDIlAgQbh3gHA7o/jxY4gx+BBAOYBZUmgio X-IPAS-Result: AgcBAOgBV1I+DYBDl2dsb2JhbABZgmaBK8EvgSUWDgEBAQEBCBYHPIIlAQEBAwEnE0QLAgEIGAoUEDIlAgQbh3gHA7o/jxY4gx+BBAOYBZUmgio X-IronPort-AV: E=Sophos;i="4.90,1074,1371074400"; d="scan'208";a="36469010" Received: from outmail128067.authsmtp.com ([62.13.128.67]) by mail2-smtp-roc.national.inria.fr with ESMTP; 10 Oct 2013 21:42:02 +0200 Received: from mail-c235.authsmtp.com (mail-c235.authsmtp.com [62.13.128.235]) by punt10.authsmtp.com (8.14.2/8.14.2) with ESMTP id r9AJg26Q013652 for ; Thu, 10 Oct 2013 20:42:02 +0100 (BST) Received: from romulus.metastack.com (cpc1-cmbg5-0-0-cust241.5-4.cable.virginmedia.com [81.98.252.242]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id r9AJg1np084117 for ; Thu, 10 Oct 2013 20:42:01 +0100 (BST) Received: from remus.metastack.local (remus.metastack.com [172.16.0.1]) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id r9AJg0h3018849 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL) for ; Thu, 10 Oct 2013 20:42:00 +0100 Received: from Remus.metastack.local ([fe80::547c:3c42:e1da:eda2]) by Remus.metastack.local ([fe80::547c:3c42:e1da:eda2%10]) with mapi id 14.03.0158.001; Thu, 10 Oct 2013 20:42:00 +0100 From: David Allsopp To: Ocaml Mailing List Thread-Topic: [Caml-list] Pattern matching on refs Thread-Index: AQHOxe1nmkpIYQRMD0W9MjoXZywNw5nuU/tw Date: Thu, 10 Oct 2013 19:42:00 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.0.18] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 172.16.0.20 X-Server-Quench: 0896257e-31e4-11e3-b802-002590a15da7 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCd1ZAARAlZZVg1f DC4bFwdFRBksPQFF ChxFJgxfNlEAUAAU NkdBMnJSNkcdTBdX QSgKW0srAxluW2N0 aBpTbQ9ZYEBOXkti UVZASkxQEQd2AxgD GRwbTRk8NQw3Ailx OwZiVnRaXUM0d054 SgBUHWQAZ2JnPX0c URVcagJVJQBXLBdF aE1/VHEIaGVWZ380 FlAlBR1jdQZ0ISFR BwUMNk4nCX4CAiIx XRZKGDwzFk0EQSp7 KBpuMFMSBy4I X-Authentic-SMTP: 61633634383431.1023:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 81.98.252.242/25 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. Subject: RE: [Caml-list] Pattern matching on refs Yotam Barnoy wrote: > I recently found out how ugly it is to pattern-match on a ref, > using {contents=3D...}. This should be extremely easy to fix in > the parser. Can it please be put into the next version of ocaml? I imagine there are those who might suggest that the ugliness of pattern ma= tching on refs is part of the discouragement against using them! > match x with > | ref y -> ... I'm guessing that you're really pattern matching with refs inside tuples or= something which makes using !x impractical? That said, if you've ended wit= h up (foo, bar, baz) where at least one of those is a reference, why not co= nsider using records with mutable fields? While writing this, Yotam Barnoy wrote: > It wouldn't solve the problem, because in reality=20 > I'm matching something like this piece of code=20 > implementing a doubly-linked list: > > type 'a cell =3D { data : 'a; > next : 'a link ref; > last : 'a link ref; > } Completely ignoring why you might be implementing linked lists in a list-pr= ocessing language (I'm sure there's a good reason!), why not have type 'a cell =3D {data: 'a; next: mutable 'a link; last: mutable 'link} ? The parser change you propose is probably not trivial - for a start, "ref" = is part of the Pervasives module, not part of the grammar, and [ref] itself= can be redefined (try [let ref x =3D x] in the toplevel). Putting somethin= g into the grammar to allow pattern matching on ref like this would at best= be a grim hack. David=20