caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Announcing dyn.alpha01
@ 2009-10-06  3:24 Till Varoquaux
  0 siblings, 0 replies; only message in thread
From: Till Varoquaux @ 2009-10-06  3:24 UTC (permalink / raw)
  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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-10-06  3:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-06  3:24 Announcing dyn.alpha01 Till Varoquaux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).