caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yoann Padioleau <padator@wanadoo.fr>
To: Samuel Mimram <samuel.mimram@ens-lyon.org>
Cc: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>,
	caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] is this a bug ?
Date: Tue, 09 May 2006 15:30:41 +0200	[thread overview]
Message-ID: <87u07zwcji.fsf@wanadoo.fr> (raw)
In-Reply-To: <446096F0.6000405@ens-lyon.org> (Samuel Mimram's message of "Tue, 09 May 2006 15:19:44 +0200")

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


  parent reply	other threads:[~2006-05-09 13:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-09 13:09 Christophe Raffalli
2006-05-09 13:16 ` [Caml-list] " Remi Vanicat
2006-05-09 13:19 ` Samuel Mimram
2006-05-09 13:26   ` Christophe Raffalli
2006-05-09 13:33     ` Samuel Mimram
2006-05-09 13:30   ` Yoann Padioleau [this message]
2006-05-09 13:22 ` Christophe Raffalli
2006-05-09 13:33 ` Luc Maranget
2006-05-09 13:47 ` Arne Ehrlich
2006-05-09 18:24   ` Jonathan Roewen
2006-05-09 13:47 ` Alain Frisch
  -- strict thread matches above, loose matches on Subject: below --
2007-05-01 12:59 Is this a bug? Thomas Fischbacher
2007-05-01 13:34 ` [Caml-list] " Eric Cooper
2007-05-02  0:25 ` Jacques Garrigue
2007-05-02  0:50   ` Thomas Fischbacher
2007-05-02  2:40     ` Jacques GARRIGUE
2002-07-08 19:53 [Caml-list] productivity improvement Oleg
2002-07-10 15:39 ` John Max Skaller
2002-07-12 12:16   ` [Caml-list] Is this a bug? John Max Skaller
2002-07-12 14:05     ` Xavier Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87u07zwcji.fsf@wanadoo.fr \
    --to=padator@wanadoo.fr \
    --cc=caml-list@inria.fr \
    --cc=christophe.raffalli@univ-savoie.fr \
    --cc=samuel.mimram@ens-lyon.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).