Browse thread
RE: [Caml-list] Warning: this match case is unused.
- Krishnaswami, Neel
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Krishnaswami, Neel <neelk@c...> |
| Subject: | RE: [Caml-list] Warning: this match case is unused. |
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