From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id MAA07636; Fri, 6 Sep 1996 12:02:16 +0200 Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.7.1/8.7.1) with ESMTP id MAA28743; Fri, 6 Sep 1996 12:00:53 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id LAA07420 for caml-redistribution; Fri, 6 Sep 1996 11:58:53 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id LAA06640 for ; Fri, 6 Sep 1996 11:27:13 +0200 Received: from news2.tokyo.intervia.ad.jp (news2.tokyo.intervia.ad.jp [202.235.64.84]) by concorde.inria.fr (8.7.1/8.7.1) with SMTP id LAA28023 for ; Fri, 6 Sep 1996 11:27:10 +0200 (MET DST) Received: from sparc1.nextsolution.co.jp (sparc1.nextsolution.co.jp [202.235.80.1]) by news2.tokyo.intervia.ad.jp (8.6.12+2.4W/intervia-1.7u) with SMTP id SAA21726; Fri, 6 Sep 1996 18:21:36 +0900 Received: from sparc3.nextsolution.co.jp by sparc1.nextsolution.co.jp (5.x/SMI-SVR4) id AA11342; Fri, 6 Sep 1996 18:20:28 +0900 Received: by sparc3.nextsolution.co.jp (5.x/SMI-SVR4) id AA00629; Fri, 6 Sep 1996 18:20:31 +0900 Date: Fri, 6 Sep 1996 18:20:31 +0900 From: christo@nextsolution.co.jp (Frank Christoph) Message-Id: <9609060920.AA00629@sparc3.nextsolution.co.jp> To: e-posse@uniandes.edu.co Cc: caml-list@pauillac.inria.fr In-Reply-To: <322F0B89.553@isis.uniandes.edu.co> (message from Ernesto Posse on Thu, 05 Sep 1996 12:19:05 -0500) Subject: Re: Pattern Matching Sender: Pierre.Weis@inria.fr > I have a question about pattern matching. I need a function which > binds an identifier to a value in certain data structure (which is > called "heap" here). This is actually a (string * record) list. It is > not suppose to be a mutable data structure, so the binding just creates > a > new list copying the same values as the old one with the exception of > the > record to be changed. For this purpose I am using List.map (I am using > O'Caml 1.01 for Windows 95): ... > However the compiler tells me that line marked (* 1 *) is an unused case > of the match expression. I thought that maybe the problem was that the > inner id variables (the ones in the function passed to map) are > identifier > patterns therefor they are different from the parameter of the assign > function. There is no equality relationship between pattern variables and identifiers in enclosing scopes unless you make it explicit with a boolean guard. > So I tried to fix it like this: > let assign heap id obj = > List.map > ( function > (name,{ vartype = vt; contents = v; > constraints = c; dependencies = d }) > when name = id -> > (name,{ vartype = vt; contents = obj; > constraints = c; dependencies = d }) > | (name,_) as r when name <> id -> r ) > heap > And now I get the warning "this pattern-matching is not exhaustive". It's probably because the compiler doesn't know that ((x = y) or (x <> y)) is always true. The following function definition also generates a complaint: #let f = function x when x = 1 -> x | x when x <> 1 -> x+1;; Warning: this pattern-matching is not exhaustive val f : int -> int = In every compiler I know of, patterns are matched sequentially. So if you drop the guard and change the second match to: (name,_) as r -> r it should compile without a warning and have the same semantics, unless you add a new match case. ------------------------------------------------------------------------ Frank Christoph Next Solution Co. Tel: 0424-98-1811 christo@nextsolution.co.jp Fax: 0424-98-1500