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: Yoann Padioleau <padator@w...>
Subject: Re: [Caml-list] is this a bug ?
Samuel Mimram <samuel.mimram@ens-lyon.org> writes:

> Hi,
>
> 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

I am not sure because because  | ([a;_] | [_;a]) when a = b    -> 2
issues the same warning.


I think | [a;_] | [_;a] when a = b-> 2    is  parsed  as 

| ( [a;_] | [_;a])  when a = b -> 2

but that the semantic is first to look at the pattern, 
and if one is found, then look at the condition, which is too late.

'when' does not "distribute" over Or-patterns :( 



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

works.

>
> This would justify the warning and explain the behaviour...
>
> Cheers,
>
> Samuel.
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>

-- 
pad