Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Announcing dyn.alpha01

0 views
Skip to first unread message

Till Varoquaux

unread,
Oct 5, 2009, 11:24:56 PM10/5/09
to Caml-list List
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

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

0 new messages