Version française
Home     About     Download     Resources     Contact us    
Browse thread
is this a bug ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi Vanicat <remi.vanicat@g...>
Subject: Re: [Caml-list] is this a bug ?
2006/5/9, Christophe Raffalli <christophe.raffalli@univ-savoie.fr>:
>
> 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 ?

Yes. When you wrote a pattern as :  '| [a;_] | [_;a] when a = b' it
first match the pattern '| [a;_] | [_;a]' then try the condition. So
it will match [a;_] and never [_;a]. You have to wrote it as :
| [a;c] when a = b or c = b -> 2


> and print "23" instead of "22" ?

It is the same problem there. Only the first patttern to match is matched.