caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ashish Agarwal <agarwal1975@gmail.com>
To: Pal-Kristian Engstad <pal_engstad@naughtydog.com>
Cc: "yminsky@gmail.com" <yminsky@gmail.com>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] pattern matching and records vs tuples
Date: Tue, 14 Apr 2009 22:40:18 -0400	[thread overview]
Message-ID: <d8be5ae20904141940s34392460r5cb1c3bc4ad7d670@mail.gmail.com> (raw)
In-Reply-To: <49E53C8A.1090601@naughtydog.com>

[-- Attachment #1: Type: text/plain, Size: 2729 bytes --]

> let { foo; bar } = 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 =
foo; bar = bar } = x
> should only match { foo; bar }, but
>    let { foo = foo; bar =  bar; .. } = 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 = foo; bar = bar } = x
>
> should only match { foo; bar }, but
>
>     let { foo = foo; bar =  bar; .. } = 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.
>>
>>  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
>
>
>
> --
> Pål-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
>
>

[-- Attachment #2: Type: text/html, Size: 4437 bytes --]

  parent reply	other threads:[~2009-04-15  2:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-14 14:12 Yoann Padioleau
2009-04-14 16:00 ` [Caml-list] " Christophe TROESTLER
2009-04-14 16:40 ` Goswin von Brederlow
2009-04-14 16:58   ` Yoann Padioleau
2009-04-14 20:01     ` Christophe Raffalli
2009-04-15  0:44 ` Yaron Minsky
2009-04-15  1:46   ` Pal-Kristian Engstad
2009-04-15  2:37     ` Yaron Minsky
2009-04-15  2:40     ` Ashish Agarwal [this message]
2009-04-16 16:05     ` Goswin von Brederlow
2009-04-16 16:59       ` David Allsopp
2009-04-17  0:26         ` Jacques Garrigue
2009-04-17 21:12         ` Goswin von Brederlow
2009-04-15  7:41   ` blue storm
2009-04-15  9:30     ` Martin Jambon
2009-04-15 11:01       ` Yaron Minsky
2009-04-15 12:04         ` Martin Jambon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d8be5ae20904141940s34392460r5cb1c3bc4ad7d670@mail.gmail.com \
    --to=agarwal1975@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=pal_engstad@naughtydog.com \
    --cc=yminsky@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).