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: Samuel Mimram <samuel.mimram@e...>
Subject: Re: [Caml-list] is this a bug ?
Christophe Raffalli wrote:
> Samuel Mimram a écrit :
>> Christophe Raffalli wrote:
>>
>>> --------------------------------
>>> 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" ?
>>>
>>> If someone tell me this is a bug then I fill a bug report ...
>>
>> I guess that the priorities says that you should "read" the third line as
>>
>> | [a;_] | ( [_;a] when a = b ) -> 2
> 
> but the you should be allowed to write
> 
>  | ([a;_] when a = b) | ( [_;a] when a = b ) -> 2
> 
> but this results in a syntax error ...

Yes, in fact I answered too quickly. The answers would have been 22 in
both cases. Moreover,

let f x = match x with
  | z | y when y = 0 -> 0
  | _ -> 1
;;

results in "Variable y must occur on both sides of this | pattern"...

Samuel.