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.5 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 76108BBC4 for ; Wed, 15 Apr 2009 04:40:20 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlUCAKLl5ElKfSwdimdsb2JhbACCJi+KUIgrPwEBAQoJDAcPBah8gQkzCY95AQMBA4JGgTMG X-IronPort-AV: E=Sophos;i="4.38,431,1233529200"; d="scan'208";a="27693078" Received: from yx-out-2324.google.com ([74.125.44.29]) by mail1-smtp-roc.national.inria.fr with ESMTP; 15 Apr 2009 04:40:19 +0200 Received: by yx-out-2324.google.com with SMTP id 8so1636414yxb.27 for ; Tue, 14 Apr 2009 19:40:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=QX5+7ihsf6UzcgZxXG/eyeBShbTKp75+QjbkBZj1kQU=; b=XUfMCfvIqIcyA8X742tIob/NKD7S21zHKDKLaI0xVYH/2Ng9dVMoOy6+N93XVccWP0 W9GWI2w1d51TJnQ+ZgJpJdoZfg9YMRvIbY5q3J3nmJSZVtv+4Sz2VOEtdtlYmr40y8ls lf8tAdptAKAxJ420SpdlGIqFH/NE3PIpZ9REE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=AT47gNAu61km6fOZXsr3FHrnedq7wH26OMBp96DV6iWattLduOKRNBtV9lqqTqdmZV fzkWcnvPduQ9Xe/7jGZh5kEsd5JS2RjC3mjj+sJGl0jgb+Xuxg/mRQadfH3Tms6VO0Bw 3JaIp0ylGY8jNC5LzYVbJpSpR7192rVn1znCo= MIME-Version: 1.0 Received: by 10.90.26.3 with SMTP id 3mr10580561agz.27.1239763218880; Tue, 14 Apr 2009 19:40:18 -0700 (PDT) In-Reply-To: <49E53C8A.1090601@naughtydog.com> References: <87skkbuxx8.fsf@aryx.cs.uiuc.edu> <891bd3390904141744k4516f3d0y551f6c572ccadad5@mail.gmail.com> <49E53C8A.1090601@naughtydog.com> Date: Tue, 14 Apr 2009 22:40:18 -0400 Message-ID: Subject: Re: [Caml-list] pattern matching and records vs tuples From: Ashish Agarwal To: Pal-Kristian Engstad Cc: "yminsky@gmail.com" , "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=00163630efc9445adf04678edeca X-Spam: no; 0.00; foo:01 foo:01 pke:01 yaron:01 minsky:01 ocaml:01 compiler:01 compiler:01 christophe:01 troestler:01 syntax:01 notation:01 emacs:01 beginner's:01 ocaml:01 --00163630efc9445adf04678edeca Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable > let { foo; bar } =3D x > bind the variable foo to the x.foo, and bind bar to x.bar > I'd prefer to have to annotate non-exhaustive records:> let { foo =3D foo; bar =3D bar } =3D x > should only match { foo; bar }, but > let { foo =3D foo; bar =3D bar; .. } =3D x, > can match records with more labels. Both of the above are supported in SML, which I've always felt has better support for record patterns. On Tue, Apr 14, 2009 at 9:46 PM, Pal-Kristian Engstad < pal_engstad@naughtydog.com> wrote: > Honestly, I'd prefer to have to annotate non-exhaustive records: > > let { foo =3D foo; bar =3D bar } =3D x > > should only match { foo; bar }, but > > let { foo =3D foo; bar =3D bar; .. } =3D x, > > can match records with more labels. > > PKE. > > > Yaron Minsky wrote: > > On Tue, Apr 14, 2009 at 10:12 AM, Yoann Padioleau wro= te: > >> >> 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 =3D function >> { 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). The thing I've never come up with a go= od > proposal for is what would be a pleasant syntax to indicate the > exhaustiveness of the pattern match. I could imagine something terse lik= e > this: > > let {! foo =3D foo; bar =3D bar; } =3D 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 } =3D x > > bind the variable foo to the x.foo, and bind bar to x.bar. Similarly, i= t > might be nice for: > > let foo =3D 3 and bar =3D 3. in { foo;bar } > > to be equivalent to > > let foo =3D 3 and bar =3D 3. in { foo =3D foo; bar =3D bar } > > y > > > > -- > P=E5l-Kristian Engstad (engstad@naughtydog.com), > Lead Graphics & Engine Programmer, > Naughty Dog, Inc., 1601 Cloverfield Blvd, 6000 North, > Santa Monica, CA 90404, USA. Ph.: (310) 633-9112. > > "Emacs would be a far better OS if it was shipped with > a halfway-decent text editor." -- Slashdot, Dec 13. 2005. > > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --00163630efc9445adf04678edeca Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable >= let { foo; bar } =3D x
> bind the variable foo to the x.foo, and bin= d bar to x.bar

>=A0I'd prefer to have to annota= te non-exhaustive records:
Both of the above are supported in SML, which I've always = felt has better support for record patterns.


On Tue, Apr 14, 2009 at 9:46 PM, Pal-= Kristian Engstad <pal_engstad@naughtydog.com> wrote:
=20
Honestly, I'd prefer to have to annotate non-exhaustive records:


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

should only match { foo; bar }, but

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

can match records with more labels.

PKE.


Yaron Minsky wrote:
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've never come up wi= th a good proposal for is what would be a pleasant syntax to indicate the exhaustiveness of the pattern match.=A0 I could imagine something terse like this:

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

where the ! indicates that the pattern match should be exhaustive.=A0 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

=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

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

y



--=20
P=E5l-Kristian Engstad (engstad@naughtydog.com),=20
Lead Graphics & Engine Programmer,
Naughty Dog, Inc., 1601 Cloverfield Blvd, 6000 North,
Santa Monica, CA 90404, USA. Ph.: (310) 633-9112.

"Emacs would be a far better OS if it was shipped with=20
 a halfway-decent text editor." -- Slashdot, Dec 13. 2005.


_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--00163630efc9445adf04678edeca--