Pietro Abate

ocaml

how to add a custom lexer to camlp4

Adding a custom parser in the old camlp4 (now camlp5) was relatively easy. The new camlp4 is quite different. The problem was discussed in two recent threads in the ocaml mailing list here and here.

The main point is to provide a new Lexer module with a compatible signature with the Camlp4 lexer.

Recursive subtyping revealed

The other day I read the article: "Recursive Subtyping revealed". A Functional Pearl by Gapeyev, Levin and Pierce. This is a bit of code I wrote to convince myself of the algorithm described in the paper.

You can get the article here

<code> type at = |Top |Nat |Bool |Even | Odd |Times of ( at * at ) |Arrow of ( at * at ) |Mu of ( string * at ) |Var of string

module S = SortedList.Make( struct type t = (at * at) let compare = compare let hash = Hashtbl.hash

ocamlbuild + camlp4 + ocamlfind

Recently I tried to answer to a problem posed on the OCaml mailing list. Basically the problem is how to compile using ocamlbuild using ocamlfind and camlp4. The Camlp4 wiki has already all the ingredients. Here I mix them up in a short example.

  1. _tags : is the ocamlbuild dep file
  2. bar.ml : is a ml file that uses the syntax extension pa_float to compile.
  3. foo.ml : is a ml file that depends on bar.ml and the str module (fetched via ocamlfind)
  4. pa_float.ml : is the source code of the camlp4 syntax extension.

The code

_tags <code>

Patch to mod-caml

I've done a bit of work to use mod-caml with apache 2.2 . I've uploaded everything on the debian gforge website alioth.

to recompile the package you can get it via svn

svn co svn://svn.debian.org/svn/pkg-ocaml-maint/trunk/packages/mod-caml

Then you can compile the package with svn-buildpackage.

I've also wrote a small patch to recursively load dependent modules. I attached a simple loader module that is partially a rip-off of some GPL code I found on the net.