[cwn] Attn: Development Editor, Latest OCaml Weekly News

Alan Schmitt alan.schmitt at polytechnique.org
Tue May 26 05:49:45 PDT 2015


Hello,

Here is the latest OCaml Weekly News, for the week of May 19 to 26, 2015.

1) GADTs and JSON
2) Job: Ocaml Engineer in Paris
3) Other OCaml News

========================================================================
1) GADTs and JSON
Archive: <https://sympa.inria.fr/sympa/arc/caml-list/2015-05/msg00081.html>
------------------------------------------------------------------------
** Trevor Smith asked and Rodolphe Lepigre replied:

> Is it possible to encode a recursive, heterogenous map and list datastructure
> with GADTs?
> 
> I want to encode JSON (there are already a couple of great libraries out there
> so this is kind of an academic question). I would like to have functions that
> can only take a JSON map type, for example to take a json map and return a
> value. The key here is that the map can hold values of type int,string and also
> maps. Is this possible?
> 
> eg get : (map : map json) -> key:string -> 'a json
> 
> Thank you.
> 
> Trevor

You should probably have a look at the examples given for GADTs on the page
about language extensions (advanced examples section):

<http://caml.inria.fr/pub/docs/manual-ocaml-400/manual021.html#toc85>

Not so long ago I used equality types to encode collections of object of
different types. Here is an example with lists and a function for obtaining
the n-th element.

##########
type (_,_) eq = Eq : ('a,'a) eq

type 'a typ =
  | Int   : int typ
  | Float : float typ
  | Pair  : 'a typ * 'b typ -> ('a * 'b) typ

let rec equal : type a b. a typ -> b typ -> (a,b) eq option = fun t1 t2 ->
  match (t1,t2) with
  | (Int       , Int      ) -> Some Eq
  | (Float     , Float    ) -> Some Eq
  | (Pair(a,b) , Pair(c,d)) ->
      begin
        match (equal a c, equal b d) with
        | (Some Eq, Some Eq)  -> Some Eq 
        | _                   -> None
      end
  | _                       -> None

type _ tlist' =
  | Nil  : unit tlist'
  | Cons : ('a typ * 'a * unit tlist') -> unit tlist'

type tlist = unit tlist'

let rec nth : type a. tlist -> int -> a typ -> a = fun l n ty ->
  match (l, n) with
  | (Nil          , _) -> raise Not_found
  | (Cons(ty',t,_), 0) ->
      begin
        match equal ty ty' with
        | Some Eq -> t
        | None    -> invalid_arg "Ill type in nth"
      end
  | (Cons(_,_,l)  , _) -> nth l (n-1) ty

let l = Cons(Int, 3, Cons(Float, 4.2, Nil))

let n : int   = nth l 0 Int
let f : float = nth l 1 Float
##########
      
========================================================================
2) Job: Ocaml Engineer in Paris
Archive: <https://sympa.inria.fr/sympa/arc/caml-list/2015-05/msg00083.html>
------------------------------------------------------------------------
** Vincent Balat announced:

The Ocsigen team is looking for a full time OCaml developer with good OCaml
skills to work on the development of a Web application using Ocsigen (Eliom +
Js_of_ocaml) in a start-up located in Paris.

Please contact me for more information!
      
========================================================================
3) Other OCaml News
------------------------------------------------------------------------
** From the ocamlcore planet blog:

Thanks to Alp Mestan, we now include in the OCaml Weekly News the links to the
recent posts from the ocamlcore planet blog at <http://planet.ocaml.org/>.

ICFP programming contest 2014: a retrospective (part 2/2):
  <http://gallium.inria.fr/blog/icfp-contest-2014-retrospective-2>

Church Numerals:
  <http://blog.shaynefletcher.org/2015/05/church-numerals.html>

On the book "More OCaml":
  <http://www.amazon.com/review/R7DMDHZMOKS8X>

ICFP programming contest 2014: a retrospective (part 1/2):
  <http://gallium.inria.fr/blog/icfp-contest-2014-retrospective-1>

Labeled and optional arguments:
  <http://blog.shaynefletcher.org/2015/03/labeled-and-optional-arguments.html>

The troublesome reflection rule (TYPES 2015 slides):
  <http://math.andrej.com/2015/05/19/the-troublesome-reflection-rule-types-2015-slides/>
      
========================================================================
Old cwn
------------------------------------------------------------------------

If you happen to miss a CWN, you can send me a message
(alan.schmitt at polytechnique.org) and I'll mail it to you, or go take a look at
the archive (<http://alan.petitepomme.net/cwn/>) or the RSS feed of the
archives (<http://alan.petitepomme.net/cwn/cwn.rss>). If you also wish
to receive it every week by mail, you may subscribe online at
<http://lists.idyll.org/listinfo/caml-news-weekly/> .

========================================================================

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/caml-news-weekly/attachments/20150526/23df4ea8/attachment.pgp>


More information about the caml-news-weekly mailing list