* Re: [Caml-list] Warning: this match case is unused.
@ 2001-11-09 6:39 Rolf Wester
0 siblings, 0 replies; 5+ messages in thread
From: Rolf Wester @ 2001-11-09 6:39 UTC (permalink / raw)
To: caml-list
Thanks to all who replied. Your answers where very instructive
for me and I hopefully now got how pattern matching works.
Thanks again
Rolf Wester
-------------------------------------
Rolf Wester
rolf.wester@ilt.fraunhofer.de
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [Caml-list] Warning: this match case is unused.
@ 2001-11-08 16:29 Krishnaswami, Neel
0 siblings, 0 replies; 5+ messages in thread
From: Krishnaswami, Neel @ 2001-11-08 16:29 UTC (permalink / raw)
To: 'Rolf Wester', caml-list
Rolf Wester [mailto:rolf.wester@ilt.fhg.de] wrote:
>
> this is probably a trivial question but can someone tell me why:
>
> let f l n0 =
> let n = List.length l in
> match n with
> n0 -> 1;
> | _ -> 0;;
>
> Results in:
> Warning: this match case is unused.
Yes. Your function will always return 1, because variables on the
left-hand side of a pattern-match are bound like in a let expression.
So the first branch of the match will always succeed, binding n0 to n,
and then return 1.
So your code is equivalent to:
let f l n0 =
let n = List.length l in
let n0 = n
in 1
which is probably not what you want. :) Try writing this as:
let f l n0 =
let n = List.length l in
if n = n0 then
1
else
0
--
Neel Krishnaswami
neelk@cswcasa.com
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Warning: this match case is unused.
2001-11-08 14:55 Rolf Wester
2001-11-08 16:14 ` Pixel
@ 2001-11-08 16:21 ` Yann Coscoy
1 sibling, 0 replies; 5+ messages in thread
From: Yann Coscoy @ 2001-11-08 16:21 UTC (permalink / raw)
To: caml-list
Rolf Wester wrote:
> Hi,
>
> this is probably a trivial question but can someone tell me why:
>
> let f l n0 =
> let n = List.length l in
> match n with
> n0 -> 1;
> | _ -> 0;;
>
> Results in:
> Warning: this match case is unused.
The second n0 in pattern « n0 -> 1 » is the introduction of a fresh
variable. It is not binded to n0 previously introduced in « f l n0 = ».
I guess the function you had in mind is:
let f l n0 =
let n = List.length l in
match n with
n1 when n1=n0 -> 1;
| _ -> 0;;
--
Yann Coscoy - Trusted Logic
5 rue du Bailliage 78000 Versailles
+33 (0) 1 30 97 74 76
http://www.trusted-logic.fr
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Warning: this match case is unused.
2001-11-08 14:55 Rolf Wester
@ 2001-11-08 16:14 ` Pixel
2001-11-08 16:21 ` Yann Coscoy
1 sibling, 0 replies; 5+ messages in thread
From: Pixel @ 2001-11-08 16:14 UTC (permalink / raw)
To: Rolf Wester; +Cc: caml-list
"Rolf Wester" <rolf.wester@ilt.fhg.de> writes:
> match n with
> n0 -> 1;
> | _ -> 0;;
make it
match n with
n0' when n0 = n0' -> 1;
| _ -> 0;;
:)
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Caml-list] Warning: this match case is unused.
@ 2001-11-08 14:55 Rolf Wester
2001-11-08 16:14 ` Pixel
2001-11-08 16:21 ` Yann Coscoy
0 siblings, 2 replies; 5+ messages in thread
From: Rolf Wester @ 2001-11-08 14:55 UTC (permalink / raw)
To: caml-list
Hi,
this is probably a trivial question but can someone tell me why:
let f l n0 =
let n = List.length l in
match n with
n0 -> 1;
| _ -> 0;;
Results in:
Warning: this match case is unused.
Thanks
Rolf Wester
-------------------------------------
Rolf Wester
rolf.wester@ilt.fraunhofer.de
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-11-09 7:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-09 6:39 [Caml-list] Warning: this match case is unused Rolf Wester
-- strict thread matches above, loose matches on Subject: below --
2001-11-08 16:29 Krishnaswami, Neel
2001-11-08 14:55 Rolf Wester
2001-11-08 16:14 ` Pixel
2001-11-08 16:21 ` Yann Coscoy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox