Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Sébastien Hinderer" <Sebastien.Hinderer@ens-lyon.org>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] A basic question
Date: Thu, 30 Dec 2004 04:29:07 +0100	[thread overview]
Message-ID: <20041230032907.GA3720@galois> (raw)
In-Reply-To: <2145c6e80412291847c40fc92@mail.gmail.com>

Hi,

> 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".

This is because, for pattern-matching to work, the two lists _must_
have the same length, so that the nth element in the right-hand list can
be assigned to the nth variable specified in the left-hand list.
But, the compiler has no way to check that in every case, hence this warning.

> I think they just setting values for x, y, and z.

Of course, it is probably possible to find some heuristics to check the
equality between lengths, making your first example work, but it'd be
tricky.
Concerning your second example, it is not that obvious to attach a good
semantics to what you write, because the lists are of different lengths.

Now, if the only thing you want to do is to assign values to several
variables at the same time, you can do something like : 
let (x, y z) = (1, 2, 3);;

Of course, the types of (x y, z) and (1, 2, 3) must be compatible.
So, a phrase like 

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

is wrong.

hth,
Sébastien.


  reply	other threads:[~2004-12-30  3:30 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 ` Sébastien Hinderer [this message]
2004-12-30  3:38 ` [Caml-list] " skaller
2004-12-30 10:28 ` Luc Maranget
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=20041230032907.GA3720@galois \
    --to=sebastien.hinderer@ens-lyon.org \
    --cc=caml-list@yquem.inria.fr \
    /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