From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 51C89BB81 for ; Thu, 30 Dec 2004 04:38:15 +0100 (CET) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBU3cDdH003007 for ; Thu, 30 Dec 2004 04:38:14 +0100 Received: from [192.168.1.200] (ppp194-89.lns1.syd2.internode.on.net [203.122.194.89]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id iBU3c7RF056296; Thu, 30 Dec 2004 14:08:07 +1030 (CST) Subject: Re: [Caml-list] A basic question From: skaller Reply-To: skaller@users.sourceforge.net To: Kathy Chen Cc: caml-list@yquem.inria.fr In-Reply-To: <2145c6e80412291847c40fc92@mail.gmail.com> References: <2145c6e80412291847c40fc92@mail.gmail.com> Content-Type: text/plain Organization: Message-Id: <1104377886.22405.95.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 30 Dec 2004 14:38:06 +1100 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41D37825.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 sourceforge:01 wrote:01 rhs:01 recursive:01 expansions:01 ocaml:01 arrays:01 arrays:01 externally:01 glebe:01 061:98 arbitrary:01 nsw:01 typing:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: On Thu, 2004-12-30 at 13:47, Kathy Chen wrote: > 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? It's a shortcoming of the type system. The RHS is just a list. The fact it has 3 elements in it is lost by the type system. The let is then matching a list of 3 elements against a list of unknown number of elements.. which isn't exhaustive. The same example using tuples will work: let x,y,z = 1,2,3 without a warning because the number (and type) of elements in a tuple is known to the type system. The difficulty comes from the 'weak' interpretation of recursive types as the union of all expansions. For 'lists' a stronger interpretation would be useful, and is equivalent to the notion of an array of some length (however Ocaml arrays are distinct types which don't have lengths either). C++ therefore has a 'stronger' type system in this respect, since arrays of definite length exist. However, the generalisation to arbitrary inductive types is probably not so useful as arrays: the length of an array is a single value, to describe the structure of a finite tree would require a lot of extra data in the type system. FYI: as an experiment, Felix has algebraic arrays. They are identical to tuples of n elements from a typing viewpoint (however internally the representation is distinct, and externally the generated code is too). -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net