caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: maranget@yquem.inria.fr (Luc Maranget)
To: Kathy Chen <kathy08@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] A basic question
Date: Thu, 30 Dec 2004 11:28:57 +0100	[thread overview]
Message-ID: <20041230102857.GA11949@yquem.inria.fr> (raw)
In-Reply-To: <2145c6e80412291847c40fc92@mail.gmail.com>

> Hi, all,
> 
> I'm a newcomer here.
> I don't understand why the following two
>     let [x;y;z] = [1;2;3] ;;
> and
>     let [x;y;z] = [1;2;3;4] ;;
> have warnings: "this pattern-matching is not exhaustive".
> I think they just setting values for x, y, and z.
> 
> Could anyone pls tell me why?
> 
> Thanks.
> Kathy
> 

There is nothing special with 'let pat = e1 in e2' bindings,
they get translated to 'match e1 with pat -> e2'
[Toplevel bindings 'let p = e ;;' are similar]

Then, usual pattern matching analysis is performed.

So your question can be reformulated for instance as
'match [1;2;3] with [x;y;z] -> ....'
'match [1;2;3;4] with [x;y;z] -> ....'
yield "this pattern-matching is not exhaustive" warnings.


First notice that running the second example results in a match failure.
(I mean, the warning is useful).

Then, one can argue that, since the matched expression is constant,
matching result can be known by the compiler and that it  should
produce no warning in the first case and produce an error in the second case.
One can also argue, as Skaller does that a more sophisticated typing system
would behave similarily whatever the matched expression is.

Well, the compiler is too lazy ! So it produces a warning in both examples !

Finally as said by other contributors, a good technique for performing
several bindings at time is using tuples:

let (x,y,z) = (1,2,3);;


Hope it helps,


-- Luc Maranget


  parent reply	other threads:[~2004-12-30 10:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-30  2:47 Kathy Chen
2004-12-30  3:29 ` [Caml-list] " Sébastien Hinderer
2004-12-30  3:38 ` skaller
2004-12-30 10:28 ` Luc Maranget [this message]
2004-12-31 18:40   ` Kathy Chen

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=20041230102857.GA11949@yquem.inria.fr \
    --to=maranget@yquem.inria.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=kathy08@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).