[ Nagoya U. | Home ]

OCaml experiments

This page contains ocaml code developped for fun or out of curiosity.
Polymorphic variants and the expression problem
This is the original code developped for a paper on polymorphic variants. New examples were added more recently using recursive modules and private rows.

OO syntax extension and OO syntax extension for camlp4 3.10
Some camlp4 syntax extensions to write more compact code using objects. The new syntaxes are

Polymap and Polymap for camlp4 3.10
This is a tiny module combined with a camlp4 extension, which allows you to define polymorphic mappings, where the type of the data depends on the key.
$ ocaml camlp4o.cma pa_polymap.cmo polymap.cmo
# let m = `{x=1; y=true};;
val m : [> `x of int | `y of bool ] Polymap.t = 
# let m = `{m with z = "hello"};;
val m : [> `x of int | `y of bool | `z of string ] Polymap.t = 
# m.`y;;
- : bool = true
# `{m with x = "a"};;
    ^
Types for tag `x are incompatible
# m.`u;;
Exception: Not_found.

JG 2007.10.18