Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Two camlp4 questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-04-25 (13:18)
From: Richard Jones <rich@a...>
Subject: Two camlp4 questions
(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.


Richard Jones
Red Hat