Version française
Home     About     Download     Resources     Contact us    
Browse thread
pattern matching and records vs tuples
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Yaron Minsky <yminsky@g...>
Subject: Re: [Caml-list] pattern matching and records vs tuples
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

   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, and bind bar to   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 }