caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Two camlp4 questions
@ 2008-04-25 13:18 Richard Jones
  2008-04-25 13:58 ` [Caml-list] " Martin Jambon
  2008-04-26 12:54 ` Nicolas Pouillard
  0 siblings, 2 replies; 5+ messages in thread
From: Richard Jones @ 2008-04-25 13:18 UTC (permalink / raw)
  To: caml-list

(1) How do I match on the pattern which is literally '_' in the
original code?

    match mypatt with
    | <:patt< _ >> -> ...

seems like it matches any pattern.

(2) Is there a function hiding anywhere which tests whether a pattern
is exhaustive?  Here's the problem I have: I want to generate code
like this:

    <:expr< match $someexpr$ with $mypatt$ -> $code$ | _ -> () >>

However this gives a compile-time warning if mypatt is already
exhaustive because the second case could never be matched.  If mypatt
is already exhaustive then I'd want to generate this code instead to
avoid the warning:

    <:expr< match $someexpr$ with $mypatt$ -> $code$ >>

I hacked around it a little with this function:

  let pattern_is_exhaustive = function
  | <:patt< $lid:_$ >> -> true
  | _ -> false

but I guess you can see that this function is not a complete solution.

Rich.

-- 
Richard Jones
Red Hat


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

end of thread, other threads:[~2008-04-26 16:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-25 13:18 Two camlp4 questions Richard Jones
2008-04-25 13:58 ` [Caml-list] " Martin Jambon
2008-04-25 14:54   ` Richard Jones
2008-04-26 12:54 ` Nicolas Pouillard
2008-04-26 16:47   ` Richard Jones

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