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: luc.maranget@i...
Subject: Re: [Caml-list] is this a bug ?
> 
> hello,
> 
> --------------------------------
> let f b l = match l with
>   [] | [_] -> 1
> | [a;_] | [_;a] when a = b-> 2
            ^^^^
> | _ -> 3
Warning U: this pattern is unused.

> 
> let _ =
>   print_int (f 1 [1;2]);
>   print_int (f 1 [2;1]);
>   print_newline ()
> --------------------------------
23


> 
> Do you think this code should have a useless pattern warning and print "23" 
> instead of "22" ?
> 
> If someone tell me this is a bug then I fill a bug report ...
> 


You may object the semantics, but it is consitent w.r.t. both
documentation (deterministic left-to-right matching of or-patterns,
semantics of when as match first, then test)
and supplied warning (which you omit).

So I am tempted to say not a bug.

However, there is indeed a difficulty, if we expand or-pat as:

let f b l = match l with
| [] -> 1
| [_] -> 1
| [a;_] when a = b -> 2
| [_;a] when a = b -> 2
| _ -> 3

Then, we have the other behavior (no warning, 22).

Oups, another oddity of 'when...'

--Luc