Previous week Up Next week


Here is the latest Caml Weekly News, for the week of June 17 to 24, 2008.

  1. patterns v0.4
  2. Unsigned Integer Library update
  3. GODI News: RocketBoost is there!

patterns v0.4


Jeremy Yallop announced:
I'm pleased to announce a new release of `patterns', an OCaml
framework for writing extensions to pattern matching using Camlp4.

You can download `patterns' from

Previous releases provided specific extensions to pattern matching
("pattern guards" and "lazy patterns").  From this release onwards
"patterns" is not itself an extension, but a means for writing
extensions to pattern matching.  Some examples are provided with the

  * Pattern-matching for lazy values

    As in previous releases, but now available as an application of
    the framework rather than a hardcoded extension.

  * Conjunctive patterns

    Conjunctive patterns (as found in F#) generalise "as"-patterns.
    In standard OCaml the syntax `patt as var' may be used to bind a
    value simultaneously to both a pattern and a variable; with
    conjunctive patterns the syntax `patt & patt' may be used to bind
    a value simultaneously to two patterns.  For example,

        let ((`A a, b) & (c, `B d)) = (`A 3, `B 4) in (a,b,c,d)

    evaluates to

       (3, `B 4, `A 3, 4)

  * "Object patterns"

    Object patterns bind the results of calling an object's methods
    to other patterns during a pattern match.  This makes it more
    convenient to use objects as structurally-typed records.  The
    notation mirrors that in Jacques Garrigue's pa_oo extension.  For

        let {| x = x; y = _ |} =
           object method x = 3 method y = 4 method z = 5 end
           x + 1

    evaluates to


  * Negative patterns.

    Matching with negative patterns succeeds if the value does not
    match the pattern given.  For example,

       let nonzero = function
          | ~0 -> true
          | _  -> false
       in (nonzero 4, nonzero 0)

    evaluates to

       (true, false)

  * N+K patterns

    The infamous n+k patterns (as found in Haskell) offer a
    "Peano-number" view of integers.  Matching an integer value v
    against `patt+k' (where k is an integer literal) succeeds,
    binding patt to v-k, if v>=k.  For example

       let pred = function
          | x+1 -> x
          | 0   -> 0
       in (pred 10, pred 0)

    evaluates to

       (9, 0)

Pattern guards are gone for now.  I intend to restore them in a future
release, implemented as an application of the framework.

The "patterns" framework has the following features:

   * it makes it easy to write extensions to deep pattern matching,
     otherwise an arduous task.  For example, the entire
     implementation of lazy patterns is just a few lines of code.

   * it works with original and revised syntax.

   * pattern-matching extensions written using the framework extend
     patterns in every context in which patterns can be used:
     function, match, try/with, let, object, etc.

   * the extensions that use the framework may be used in any
     combination: for example, you can choose to use negative and n+k
     patterns in your program without loading any of the other

Users of previous versions may notice additional improvements.  For
example, "patterns" no longer modifies the OCaml grammar, so it should
coexist more happily with other extensions.

Feedback, including bug reports and patches, are very welcome.
Nathaniel Gray asked and Jeremy Yallop answered:
> Ooh, very interesting!  Have you looked at "active patterns" in F#?
> They look really useful and I've been wanting to code them up in
> camlp4 for a while now but haven't had the time.  It sounds like your
> framework could make that much easier.

Yes, one of the reason for writing the framework was to be able to implement
F#-like active patterns. I think it should be reasonably straightforward to do
-- in fact, I'd expect design considerations to take up more time than actual
implementation work (although I say that from the perspective of being already
familiar with the "patterns" framework, of course). If I remember rightly,
there's a note at the end of the ICFP07 active patterns paper about using
polymorphic variants to add active patterns in OCaml, which seems like it
might be a good starting point.

You might also be interested in the "views" feature of Martin Jambon's
"Micmatch", which is along the same lines as active patterns:
Richard Jones then asked and Martin Jambon answered:
> Is anyone working on upgrading micmatch to 3.10?

I am, but I don't spend as much time on my personal projects than I used to,
so it goes slowly.

The dev page is at
There's a subversion repository. Although the code is currently unusable
you can see if there's some progress:

Unsigned Integer Library update


Jeff Shaw announced:
I originally had problems with linking the native code but that's now fixed,
and I added a library for 32-bit unsigned integers as well. The README
contains instructions for compiling.

GODI News: RocketBoost is there!


Gerd Stolpmann announced:
GODI finally releases a new version of the core environment, code name
RocketBoost. This is now considered as being stable.

There are not many new features in this release, so there is often no
reason to switch to it if you already have GODI.

The big news is that GODI now supports the MinGW port of OCaml for
Windows (besides the Cygwin port). This means that it is now possible to
create native Windows applications with GODI. Note, however, that the
porting effort is still in its beginning - GODI itself works, but most
packages aren't ported yet, and won't work. The MinGW support is
considered as experimental, but we hope to provide a more comprehensive
set of packages in the future when O'Caml 3.11 becomes available.

The MinGW port has become possible because large parts of the GODI
core have been rewritten. In particular, the C programs accompanying
godi_console are now coded in O'Caml (godi_make, godi_add, etc.), so
porting was possible by enhancing a few O'Caml libraries. This
refactoring of GODI also increases the portability in the Unix world -
effectively it should now run on all platforms where OCaml runs, where
gcc is available, and where POSIX-compliant shell utilities are

RocketBoost is now available from

There is no way to upgrade an existing GODI installation to RocketBoost
due to heavy changes in the GODI core.

Please read the included README for installation instructions.
Especially if you want to install on Windows read it carefully.

Note that RocketBoost still defaults to O'Caml 3.10.1. An upgrade to
3.10.2 will follow in the next days.

Using folding to read the cwn in vim 6+

Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater).

:set foldmethod=expr
:set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'<1':1

If you know of a better way, please let me know.

Old cwn

If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.

Alan Schmitt