From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: by yquem.inria.fr (Postfix, from userid 18041) id 7E7A1BB81; Thu, 30 Dec 2004 11:28:57 +0100 (CET) Date: Thu, 30 Dec 2004 11:28:57 +0100 To: Kathy Chen Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] A basic question Message-ID: <20041230102857.GA11949@yquem.inria.fr> References: <2145c6e80412291847c40fc92@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2145c6e80412291847c40fc92@mail.gmail.com> User-Agent: Mutt/1.3.28i From: maranget@yquem.inria.fr (Luc Maranget) X-Spam: no; 0.00; caml-list:01 maranget:01 luc:01 maranget:01 'let:01 bindings:01 translated:01 toplevel:01 bindings:01 'let:01 compiler:01 compiler:01 lazy:01 luc:01 ....:98 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=-2.8 required=5.0 tests=ALL_TRUSTED autolearn=disabled version=3.0.0 X-Spam-Level: > 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