From: christo@nextsolution.co.jp (Frank Christoph)
To: e-posse@uniandes.edu.co
Cc: caml-list@pauillac.inria.fr
Subject: Re: Pattern Matching
Date: Fri, 6 Sep 1996 18:20:31 +0900 [thread overview]
Message-ID: <9609060920.AA00629@sparc3.nextsolution.co.jp> (raw)
In-Reply-To: <322F0B89.553@isis.uniandes.edu.co> (message from Ernesto Posse on Thu, 05 Sep 1996 12:19:05 -0500)
> 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 = <fun>
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
next prev parent reply other threads:[~1996-09-06 10:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-09-05 17:19 Ernesto Posse
1996-09-06 8:17 ` Pierre Weis
1996-09-06 9:20 ` Frank Christoph [this message]
1997-05-01 13:34 stderr David Monniaux
1997-05-06 14:03 ` pattern matching Olivier Montanuy
1997-05-06 19:59 ` Stefan Monnier
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=9609060920.AA00629@sparc3.nextsolution.co.jp \
--to=christo@nextsolution.co.jp \
--cc=caml-list@pauillac.inria.fr \
--cc=e-posse@uniandes.edu.co \
/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