Browse thread
is this a bug ?
[
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: | Alain Frisch <Alain.Frisch@i...> |
| Subject: | Re: [Caml-list] is this a bug ? |
Christophe Raffalli wrote: > > hello, > > -------------------------------- > let f b l = match l with > [] | [_] -> 1 > | [a;_] | [_;a] when a = b-> 2 > | _ -> 3 > > let _ = > print_int (f 1 [1;2]); > print_int (f 1 [2;1]); > print_newline () > -------------------------------- > > Do you think this code should have a useless pattern warning and print > "23" instead of "22" ? Well, both happens, right? I don't see any problem. The pattern [_;a] is useless because [a;_] matches the same values and the first match (left-to-right) policy is specificed (http://caml.inria.fr/pub/docs/manual-ocaml/manual014.html). The guard is checked after the binding, and there is no backtracking. This explains why the function returns 3 when b=1 l=[2;1]. -- Alain