<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2009/10/1fa1f44e18c36509d250514c26be5736"
  from="Till Varoquaux &lt;till@p...&gt;"
  author="Till Varoquaux"
  date="2009-10-06T03:24:44"
  subject="Announcing dyn.alpha01"
  prev="2009/10/97f091be5cebf8a11a847b071d10db47"
  next="2009/10/c0015c890b908f272c4dc603b1de268a"
  prev-thread="2009/10/d364f92bdb97360d8449f027692a7ae1"
  next-thread="2009/10/c0015c890b908f272c4dc603b1de268a"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Announcing dyn.alpha01">
<msg 
  url="2009/10/1fa1f44e18c36509d250514c26be5736"
  from="Till Varoquaux &lt;till@p...&gt;"
  author="Till Varoquaux"
  date="2009-10-06T03:24:44"
  subject="Announcing dyn.alpha01">
</msg>
</thread>

<contents>
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 -&gt; t
  val dyn_of_t : t -&gt; 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
   | &lt;:dyn&lt; ()&gt;&gt;                 -&gt; &lt;:dtd&lt;unit&gt;&gt;
   | &lt;:dyn&lt; $int:_$&gt;&gt;             -&gt; &lt;:dtd&lt;int&gt;&gt;
   | &lt;:dyn&lt; $float:_$&gt;&gt;           -&gt; &lt;:dtd&lt;float&gt;&gt;
   | &lt;:dyn&lt; $bool:_$&gt;&gt;            -&gt; &lt;:dtd&lt;bool&gt;&gt;
   | &lt;:dyn&lt; $string:_$&gt;&gt;          -&gt; &lt;:dtd&lt;string&gt;&gt;
   | &lt;:dyn&lt;[]&gt;&gt;                   -&gt; &lt;:dtd&lt;unit list&gt;&gt; (* Technicaly a
'a list...*)
   | &lt;:dyn&lt; $list:(h::_)$&gt;&gt;       -&gt; &lt;:dtd&lt; $guess h$ list&gt;&gt;
     (* We should do unification to get correct results. *)
   | &lt;:dyn&lt; $record:l$&gt;&gt;          -&gt;
                    &lt;:dtd&lt; $record:(List.map (fun (name,d) -&gt;
name,guess d) l)$&gt;&gt;
   | &lt;:dyn&lt; $tup:t$ &gt;&gt;            -&gt; &lt;:dtd&lt; $tup:(List.map guess t)$&gt;&gt;
   | &lt;:dyn&lt; $variant:(n,vals)$ &gt;&gt; -&gt; &lt;:dtd&lt; $variant:[n,List.map guess vals]$&gt;&gt;


Contributions are more than welcome.

Till

</contents>

</message>

