caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Till Varoquaux <till@pps.jussieu.fr>
To: Caml-list List <caml-list@inria.fr>
Subject: Announcing dyn.alpha01
Date: Mon, 5 Oct 2009 23:24:42 -0400	[thread overview]
Message-ID: <9d3ec8300910052024y622eb9e1n124ffd0232a09447@mail.gmail.com> (raw)

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


                 reply	other threads:[~2009-10-06  3:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9d3ec8300910052024y622eb9e1n124ffd0232a09447@mail.gmail.com \
    --to=till@pps.jussieu.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).