From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 0DE5ABC0A for ; Wed, 20 Jun 2007 02:11:13 +0200 (CEST) Received: from bdmail1.accesst.com (pop.bulldoghome.com [83.245.1.230]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5K0BCZO031296 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 20 Jun 2007 02:11:12 +0200 Received: from host-84-9-232-172.bulldogdsl.com ([84.9.232.172] helo=[192.168.123.191]) by bdmail1.accesst.com with esmtpa (Exim 4.50) id 1I0ngd-0006kO-1w for caml-list@inria.fr; Wed, 20 Jun 2007 01:04:39 +0100 Message-ID: <46787172.4080404@ed.ac.uk> Date: Wed, 20 Jun 2007 01:14:42 +0100 From: Jeremy Yallop User-Agent: Mozilla-Thunderbird 2.0.0.0 (X11/20070601) MIME-Version: 1.0 To: caml-list@inria.fr Subject: ANN: pretty-printing, type-safe marshalling, dynamic typing for free. Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 467870A0.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; type-safe:01 marshalling:01 ocaml:01 syntax:01 haskell:01 type-safe:01 marshalling:01 ocaml:01 variants:01 recursive:01 constructors:01 abstr:01 abstr:01 seq:01 seq:01 I'm pleased to announce an initial release of `deriving', a system for constructing functions automatically from type definitions. Deriving extends OCaml with two new operations: a syntax for calling an "overloaded" function at a particular type: C.function v and the `deriving' construct found in Haskell (and Clean) for requesting that the implementation generate an instance of an overloaded function from a type definition: type t = r deriving (C1, C2) Deriving provides functions for pretty-printing, dynamic typing, type-safe structure-sharing marshalling, SML-style equality, mapping, and more. Functions can be generated for most OCaml types, including records, standard and polymorphic variants, tuples, mutually recursive types, and types that use abstract type constructors defined elsewhere. A few more exotic constructs, such as private types and type replication, are supported. Derived functions are also extensible: the user can choose to supply an implementation at a particular type if the generated version is not to his taste. You can find deriving (along with preliminary documentation and tests) at http://code.google.com/p/deriving/ Note: you'll need OCaml 3.10. Some examples of use follow. Pretty-printing: Show.show 3 => "3" let factors = [(10,[2;5]); (11, []); 12, [2;3;4;6]] Show.show<(int * int list) list> factors => "[(10,[2; 5]); (11, []); 12, [2; 3; 4; 6]]" type 'a tree = Leaf of 'a | Branch of 'a tree * 'a * 'a tree deriving (Show, Typeable, Eq, Shelve) type point = { x : float; y : float } deriving (Show, Typeable, Eq, Shelve) let points = Branch (Leaf {x=0.0; y=0.0;}, {x=2.0; y=2.0}, Branch (Leaf {x=1.0; y=1.0}, {x=1.0; y=0.0}, Leaf {x=0.0; y=1.0})) Show.show points => "Branch (Leaf {x =193.11; y =132.13}, {x =211.91; y =201.11}, Branch (Leaf {x =113.12; y =1.}, {x =12.7; y =44.1}, Leaf {x =0.; y =13.41}))" Dynamic typing: let items = [Typeable.mk 3; Typeable.mk 3.0; Typeable.mk (Leaf "three")] => [; ; ] Typeable.cast (List.hd items) => Some 3 Typeable.cast (List.hd items) => None Dynamic typing again: type 'a seq = [`Nil | `Cons of 'a * 'a seq] deriving (Typeable) let l = `Cons (3, `Cons (2, `Cons (1, `Nil))) Typeable.cast<[`Cons of int * 'a|`Nil] as 'a> (Typeable.mk l) => Some (`Cons (3, `Cons (2, `Cons (1, `Nil)))) Serialisation (marshalling): Shelve.shelveS points => "\007\003\t\128\128\128\128\128\128\128\248?\t\128\128\128\128\128\128\128\128@\001\000\005\000\001\008\000\001\n\001\003\004\t\003\000\001\012\001\003\006\011\005\005\002\002\000\002\000\002\002\000\000\002\001\001\002\002\002" Shelve.unshelveS (Shelve.shelveS points) => Branch (Leaf {x =193.11; y =132.13}, {x =211.91; y =201.11}, Branch (Leaf {x =113.12; y =1.}, {x =12.7; y =44.1}, Leaf {x =0.; y =13.41})) Shelve.unshelveS (Shelve.shelveS points) => *** Exception For more see the documentation and test suite. Comments, bug reports, and other feedback will be most welcome. Jeremy.