caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* "Warning U: this match case is unused." -- Yes, I know
@ 2008-02-27 21:32 David Teller
  2008-02-27 21:48 ` [Caml-list] " Till Varoquaux
  2008-02-27 22:09 ` Edgar Friendly
  0 siblings, 2 replies; 6+ messages in thread
From: David Teller @ 2008-02-27 21:32 UTC (permalink / raw)
  To: OCaml

   Dear list,

 I'm currently working on a little Camlp4 extension which has to often
generate pattern-matching clauses depending on user code -- and deal
with match failures accordingly. 

Now, I guess

1. I can wrap the user's pattern-matching inside a try...with, catch any
Match_failure and deal with it. However, ensuring that the Match_failure
is the right one and that I'm not catching some other error in the code,
all this while performing bindings satisfactorily will require numerous
contorsions.

2. I can add a catch-all clause " _ -> deal_with_error ". While the
semantics of this rewriting are exactly what I need, the compiler tends
to print "Warning U: this match case is unused" whenever the user has
already taken care of all cases. I would need to find a way to
deactivate the warning for this specific clause. As I haven't found any
way of doing that directly, I've been thinking about adding a "when
True" to the second-to-last clause if that clause doesn't already have a
"when", but I'd be glad to hear about better solutions.

Thanks in advance,
 David

-- 
David Teller
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act brings liquidations. 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] "Warning U: this match case is unused." -- Yes, I know
  2008-02-27 21:32 "Warning U: this match case is unused." -- Yes, I know David Teller
@ 2008-02-27 21:48 ` Till Varoquaux
  2008-02-27 21:56   ` David Teller
  2008-02-27 22:09 ` Edgar Friendly
  1 sibling, 1 reply; 6+ messages in thread
From: Till Varoquaux @ 2008-02-27 21:48 UTC (permalink / raw)
  To: David Teller; +Cc: OCaml

There is a function in camlp4 that checks for this:
Ast.is_irrefut_patt
Check that you have a recent ocaml. It used to be bugged (it was fixed
in mid september).

Cheers

On Wed, Feb 27, 2008 at 9:32 PM, David Teller
<David.Teller@univ-orleans.fr> wrote:
>    Dear list,
>
>   I'm currently working on a little Camlp4 extension which has to often
>  generate pattern-matching clauses depending on user code -- and deal
>  with match failures accordingly.
>
>  Now, I guess
>
>  1. I can wrap the user's pattern-matching inside a try...with, catch any
>  Match_failure and deal with it. However, ensuring that the Match_failure
>  is the right one and that I'm not catching some other error in the code,
>  all this while performing bindings satisfactorily will require numerous
>  contorsions.
>
>  2. I can add a catch-all clause " _ -> deal_with_error ". While the
>  semantics of this rewriting are exactly what I need, the compiler tends
>  to print "Warning U: this match case is unused" whenever the user has
>  already taken care of all cases. I would need to find a way to
>  deactivate the warning for this specific clause. As I haven't found any
>  way of doing that directly, I've been thinking about adding a "when
>  True" to the second-to-last clause if that clause doesn't already have a
>  "when", but I'd be glad to hear about better solutions.
>
>  Thanks in advance,
>   David
>
>  --
>  David Teller
>   Security of Distributed Systems
>   http://www.univ-orleans.fr/lifo/Members/David.Teller
>   Angry researcher: French Universities need reforms, but the LRU act brings liquidations.
>
>  _______________________________________________
>  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
>



-- 
http://till-varoquaux.blogspot.com/


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] "Warning U: this match case is unused." -- Yes, I know
  2008-02-27 21:48 ` [Caml-list] " Till Varoquaux
@ 2008-02-27 21:56   ` David Teller
  0 siblings, 0 replies; 6+ messages in thread
From: David Teller @ 2008-02-27 21:56 UTC (permalink / raw)
  To: Till Varoquaux; +Cc: OCaml

Thanks, but to the best of my knowledge, irrefutable patterns and
Match_failure / Warning U are vaguely related at best. The first one is
part of the syntax while the second one depends on type definitions.

Cheers,
 David

On Wed, 2008-02-27 at 21:48 +0000, Till Varoquaux wrote:
> There is a function in camlp4 that checks for this:
> Ast.is_irrefut_patt
> Check that you have a recent ocaml. It used to be bugged (it was fixed
> in mid september).
> 
> Cheers

-- 
David Teller
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act
brings liquidations. 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] "Warning U: this match case is unused." -- Yes, I know
  2008-02-27 21:32 "Warning U: this match case is unused." -- Yes, I know David Teller
  2008-02-27 21:48 ` [Caml-list] " Till Varoquaux
@ 2008-02-27 22:09 ` Edgar Friendly
  2008-02-27 22:21   ` David Teller
  1 sibling, 1 reply; 6+ messages in thread
From: Edgar Friendly @ 2008-02-27 22:09 UTC (permalink / raw)
  To: David Teller; +Cc: OCaml

David Teller wrote:
>    Dear list,
> 
>  I'm currently working on a little Camlp4 extension which has to often
> generate pattern-matching clauses depending on user code -- and deal
> with match failures accordingly. 
> 
> Now, I guess
> 
> 1. I can wrap the user's pattern-matching inside a try...with, catch any
> Match_failure and deal with it. 
This seems hackish.

> 2. I can add a catch-all clause " _ -> deal_with_error ". While the
> semantics of this rewriting are exactly what I need, the compiler tends
> to print "Warning U: this match case is unused" whenever the user has
> already taken care of all cases. 
It may seem that you've taken care of all cases, but keep in mind that
the compiler looks at a match case containing a 'when' clause and
assumes that clause can cause the match to fail, independent of all
other terms.

i.e. if you write:
match 123 with
	| x when x mod 2 = 1 -> "Odd"
	| x when x mod 2 = 0 -> "Even"

The compiler can't see that you've covered all cases.  Even the
following generates a warning:
match 123 with x when true -> "TRUE" | x when false -> "FALSE"

The way I write this style of matching goes like this:
match 123 with
	| x when x mod 2 = 1 -> "Odd"
	| x (* x mod 2 = 0 *) -> "Even"

Can you structure your matches this way?

E.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] "Warning U: this match case is unused." -- Yes, I know
  2008-02-27 22:09 ` Edgar Friendly
@ 2008-02-27 22:21   ` David Teller
  2008-02-27 22:30     ` Edgar Friendly
  0 siblings, 1 reply; 6+ messages in thread
From: David Teller @ 2008-02-27 22:21 UTC (permalink / raw)
  To: Edgar Friendly; +Cc: OCaml

On Wed, 2008-02-27 at 16:09 -0600, Edgar Friendly wrote:
> > 1. I can wrap the user's pattern-matching inside a try...with, catch any
> > Match_failure and deal with it. 
> This seems hackish.

Indeed. I'm not planning to carry on that threat :)

> It may seem that you've taken care of all cases, but keep in mind that
> the compiler looks at a match case containing a 'when' clause and
> assumes that clause can cause the match to fail, independent of all
> other terms.

Let me rephrase.

In my extension, the user can decide of *any* pattern. The main
difference with usual OCaml-style pattern-matching is that the
equivalent of Match_failure is not a fatal error. Think Erlang-style
mailbox-checking or ML-style exception catching: if there's no
interesting message waiting or if we're installing an exception handler
for another exception than what has been raised, well, it's probably not
an error. 

So I need to be able to specify what happens in case of match failure.
Doing that is a one-liner, I can just add 
  | _ -> foobar
after my last match case. Now, I just want to get rid of Warning U.

Cheers,
 David


-- 
David Teller
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act
brings liquidations. 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] "Warning U: this match case is unused." -- Yes, I know
  2008-02-27 22:21   ` David Teller
@ 2008-02-27 22:30     ` Edgar Friendly
  0 siblings, 0 replies; 6+ messages in thread
From: Edgar Friendly @ 2008-02-27 22:30 UTC (permalink / raw)
  To: David Teller; +Cc: OCaml

David Teller wrote:
> So I need to be able to specify what happens in case of match failure.
> Doing that is a one-liner, I can just add 
>   | _ -> foobar
> after my last match case. Now, I just want to get rid of Warning U.
> 
> Cheers,
>  David

The 'when true' trick seems as reasonable as you'll get to disable that
warning, unless you have the ability to pass -Wu to the compiler to
disable that warning.

E


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-02-27 22:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-27 21:32 "Warning U: this match case is unused." -- Yes, I know David Teller
2008-02-27 21:48 ` [Caml-list] " Till Varoquaux
2008-02-27 21:56   ` David Teller
2008-02-27 22:09 ` Edgar Friendly
2008-02-27 22:21   ` David Teller
2008-02-27 22:30     ` Edgar Friendly

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).