Browse thread
Announcing dyn.alpha01
- Till Varoquaux
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2009-10-06 (03:24) |
From: | Till Varoquaux <till@p...> |
Subject: | Announcing dyn.alpha01 |
I am please to announce the release of dyn (homepage https://forge.ocamlcore.org/projects/dyn/). This release is made possible by Jane Street capital who opened up the initial code. Dyn is a camlp4 syntax extension for Ocaml that: - Scaffolds injection and projection functions to an from dynamicaly typed values (`dyn`). - Reifies ocaml type representation in run-time inspectable values (`dtd`). - Provides camlp4 quotations/antiquotations to work with `dyn`s and `dtd`s. When the `pa_dyn` syntax is loaded it adds a new `type_conv` type processor that can be called by appending `with dyn` after a type definition (e.g. `type t = ... with dyn`) three values are defined: val t_of_dyn : Dyn.Data.t -> t val dyn_of_t : t -> Dyn.Data.t val dtd_of_t : Dyn.DTD.t Dynamic values (`dyn`) ---------------------- Dynamic values are represented using the ocaml type `Dyn.Data.t`: | Unit | Int of int | Float of float | Bool of bool | String of string | List of t list | Record of (string * t) list | Tuple of t list | Variant of string * t list Type representations (`dtd`) ---------------------------- The types for the `dtd`s is `Dyn.Dtd.t`. It is a straightforward mapping to `Dyn.Data.t`. Unique id and laziness are used to deal with recursive types. Quotations and antiquotations ------------------------------ The syntax extension also has experimental support for quotations and anti-quotations as syntactic sugar for values of types `Dyn.Data.t` and `Dyn.Dtd.t` both in expressions and patterns. The following is a toy function that extracts types from values using quotations and anti-quotations: let rec guess = function | <:dyn< ()>> -> <:dtd<unit>> | <:dyn< $int:_$>> -> <:dtd<int>> | <:dyn< $float:_$>> -> <:dtd<float>> | <:dyn< $bool:_$>> -> <:dtd<bool>> | <:dyn< $string:_$>> -> <:dtd<string>> | <:dyn<[]>> -> <:dtd<unit list>> (* Technicaly a 'a list...*) | <:dyn< $list:(h::_)$>> -> <:dtd< $guess h$ list>> (* We should do unification to get correct results. *) | <:dyn< $record:l$>> -> <:dtd< $record:(List.map (fun (name,d) -> name,guess d) l)$>> | <:dyn< $tup:t$ >> -> <:dtd< $tup:(List.map guess t)$>> | <:dyn< $variant:(n,vals)$ >> -> <:dtd< $variant:[n,List.map guess vals]$>> Contributions are more than welcome. Till