Tywith OCaml Module
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.
Project
Active Tickets
Assembla Project Page
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 TywithExample.
For a complete list of local wiki pages, see TitleIndex.