From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=5.0 tests=AWL,DNS_FROM_RFC_POST, HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id E731FBBC4 for ; Wed, 15 Apr 2009 02:44:32 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgoAAOvK5EnRVYT0oWdsb2JhbACCJDGSez8BAQEBAQEHCQoCBxGodAeBApAsAQMBA4N5BoVR X-IronPort-AV: E=Sophos;i="4.40,188,1238968800"; d="scan'208";a="24592238" Received: from an-out-0708.google.com ([209.85.132.244]) by mail2-smtp-roc.national.inria.fr with ESMTP; 15 Apr 2009 02:44:32 +0200 Received: by an-out-0708.google.com with SMTP id c2so1692590anc.27 for ; Tue, 14 Apr 2009 17:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:reply-to:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=H9CYjSckuRHybgITunyp9lPyH24kS0v16VPLBvQIO5Q=; b=tZkXgW2oLCbaeXmdpqHeyYKh6HEyN36CEwxEo+1OlhuWGdpbmTIDPTqlLnXxZ0d7Ui oR6hove33lMKCEKlE4mmDu9isNBY+MGC55lsaXB4exBdSqKCZ7JgANWH+QnJAoSNZSy6 KPquPYxLw106PXeaq5IWDpfVIQelbNHPl1gvM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; b=es0k/plsylf2U/D7lcc8PG8Uaj2LWUD49YW8TXRBEmDkNNOuhM/m8stXl3IPAPsnY8 Q8fwgmxu4VX/7qJoPJuBc4qiYax2loE6UWID8RRDIKFRwvUjuMfEoF7iiStZAZE4s20d 4U1E7iXRt1SnnOaRPKD99GJzUOGkVC5fZEcwI= MIME-Version: 1.0 Received: by 10.101.68.19 with SMTP id v19mr7416996ank.70.1239756271377; Tue, 14 Apr 2009 17:44:31 -0700 (PDT) Reply-To: yminsky@gmail.com In-Reply-To: <87skkbuxx8.fsf@aryx.cs.uiuc.edu> References: <87skkbuxx8.fsf@aryx.cs.uiuc.edu> Date: Tue, 14 Apr 2009 20:44:31 -0400 Message-ID: <891bd3390904141744k4516f3d0y551f6c572ccadad5@mail.gmail.com> Subject: Re: [Caml-list] pattern matching and records vs tuples From: Yaron Minsky To: Yoann Padioleau Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=0016368e268f29de7d04678d4028 X-Spam: no; 0.00; yaron:01 minsky:01 yminsky:01 ocaml:01 compiler:01 compiler:01 foo:01 christophe:01 troestler:01 syntax:01 foo:01 notation:01 ocaml:01 christophe:01 troestler:01 --0016368e268f29de7d04678d4028 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Tue, Apr 14, 2009 at 10:12 AM, Yoann Padioleau wrote: > > So, would it be possible to extend the ocaml compiler with a simple > feature that let the programmer tell the compiler when he use > an "exhaustive" pattern with record, e.g. > > let foo = function > { field1 = v1; field2 = v2; NOTHING_ELSE} -> > I think this is a great idea (and something I've blogged about before, as Christophe Troestler points out). The thing I've never come up with a good proposal for is what would be a pleasant syntax to indicate the exhaustiveness of the pattern match. I could imagine something terse like this: let {! foo = foo; bar = bar; } = x where the ! indicates that the pattern match should be exhaustive. Such terse notation would sadly be somewhat obscure. Another thought I've had for making record matches lighter is to do the same kind of trick that's done with labeled arguments, i.e., have let { foo; bar } = x bind the variable foo to the x.foo, and bind bar to x.bar. Similarly, it might be nice for: let foo = 3 and bar = 3. in { foo;bar } to be equivalent to let foo = 3 and bar = 3. in { foo = foo; bar = bar } y --0016368e268f29de7d04678d4028 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, Apr 14, 2009 at 10:12 AM, Yoann Padioleau <padator@wanadoo.fr> wrote:=

So, would it be possible to extend the ocaml compiler with a simple
feature that let the programmer tell the compiler when he use
an "exhaustive" pattern with record, e.g.

=A0let foo =3D function
=A0{ field1 =3D v1; field2 =3D v2; NOTHING_ELSE} ->

I think this is a great idea (and something I've = blogged about before, as Christophe Troestler points out).=A0 The thing I&#= 39;ve never come up with a good proposal for is what would be a pleasant sy= ntax to indicate the exhaustiveness of the pattern match.=A0 I could imagin= e something terse like this:

=A0=A0 let {! foo =3D foo; bar =3D bar; } =3D x

where the ! indi= cates that the pattern match should be exhaustive.=A0 Such terse notation w= ould sadly be somewhat obscure.

Another thought I've had for mak= ing record matches lighter is to do the same kind of trick that's done = with labeled arguments, i.e., have

=A0=A0 let { foo; bar } =3D x

bind the variable foo to the x.foo= , and bind bar to x.bar.=A0=A0 Similarly, it might be nice for:

=A0 = =A0 let foo =3D 3 and bar =3D 3. in { foo;bar }

to be equivalent to<= br>
=A0=A0 let foo =3D 3 and bar =3D 3. in { foo =3D foo; bar =3D bar }<= br>
y

--0016368e268f29de7d04678d4028--