caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: caml-list@inria.fr
Subject: Two camlp4 questions
Date: Fri, 25 Apr 2008 14:18:12 +0100	[thread overview]
Message-ID: <20080425131812.GB4100@annexia.org> (raw)

(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


             reply	other threads:[~2008-04-25 13:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-25 13:18 Richard Jones [this message]
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

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=20080425131812.GB4100@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    /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).