Tywith OCaml Module

The Tywith module including this page has moved here.

Tywith is an OCaml camlp4 parser extension which derives functions from type definitions. It's currently capable of generating string_of_<type>, map_<type>, fold_<type>, and parser_<type> functions. It does so for (parametrized) alias, variant, and record types containing tuples, functions types and named types with the appropriate functions defined, as far as is possible. Eventually Tywith aims to provide further generators, including format box printing, and a way to plug in external generators.

Tywith special-cases built-in types such as list, int, and string to provide or use the appropriate functions.

Documentation

This package extends OCaml with the following syntactic construction

   type <def> with <id> ,<id>..*

The <id>'s currently supported are string_of, map, fold, and parse which will result in the generation of the appropriate functions.

Example

The following type definition:

  type 'a tree =
    | Leaf of 'a
    | Node of 'a tree * 'a tree
    with string_of, map, fold, parse

 
Will generate functions with the following signatures:

   val string_of_tree : ('a -> string) -> 'a tree -> string
  val map_tree : ('a -> 'b) -> 'a tree -> 'b tree
  val fold_tree : ('a -> 'b) -> ('b -> 'b -> 'b) -> 'a tree -> 'b
  val parse_tree : (char Stream.t -> 'a) -> char Stream.t -> 'a tree

The generated function code can be seen in the Tywith example.

Installation

Download the source distribution of version 0.45 from:

  http://www.guldheden.com/~sandin/files/tywith045.zip

Compile the included files:

   ocamlc -c tywith.ml
   ocamlc -c -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I +camlp4 pa_tywith.ml

Then copy them to your .../lib/ocaml/camlp4 directory.
Compile your own files using:

  ocamlc -c -pp "camlp4o pa_tywith.cmo" +camlp4 tywith.ml myfile.ml

New In Version 0.4(5)

 

Progress On Version 0.5

I have recently started to work and because of this I don't have much time to work on Tywith. I therefore decided to release a version 0.45 which contains the misc updates for Tywith were already done for version 0.5, including the "parse_<type>" functions. The rest of the features scheduled for 0.5 will arrive, as is often the case, whenever I get some time. I also intend to make Tywith available as a GODI? package, on a similar schedule.

Comments

Please leave comments and feature requests here, or send them to msandin@gmail.com.


safe mode