Previous week Up Next week


Here is the latest Caml Weekly News, for the week of June 19 to 26, 2007.

  1. pretty-printing, type-safe marshalling, dynamic typing for free.
  2. Caml code listing inside LaTeX
  3. graph

pretty-printing, type-safe marshalling, dynamic typing for free.


Jeremy Yallop announced:
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<t> 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)

Note: you'll need OCaml 3.10.

Some examples of use follow.

Pretty-printing:<int> 3

   let factors = [(10,[2;5]); (11, []);  12, [2;3;4;6]]<(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;
                        {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}))<point tree> points
      (Leaf {x =193.11; y =132.13}, {x =211.91; y =201.11},
         (Leaf {x =113.12; y =1.}, {x =12.7; y =44.1}, Leaf {x =0.; y =13.41}))"

Dynamic typing:

   let items =
      [<int> 3;<float> 3.0;<string tree> (Leaf "three")]
   [<abstr>; <abstr>; <abstr>]

   Typeable.cast<int> (List.hd items)
   Some 3

   Typeable.cast<float> (List.hd items)

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>
     (<int seq> l)
   Some (`Cons (3, `Cons (2, `Cons (1, `Nil))))

Serialisation (marshalling):

   Shelve.shelveS<point tree> points

   Shelve.unshelveS<point tree> (Shelve.shelveS<point tree> points)
     (Leaf {x =193.11; y =132.13}, {x =211.91; y =201.11},
        (Leaf {x =113.12; y =1.}, {x =12.7; y =44.1}, Leaf {x =0.;
                                                            y =13.41}))

   Shelve.unshelveS<int> (Shelve.shelveS<point tree> points)
   *** Exception

For more see the documentation and test suite.

Comments, bug reports, and other feedback will be most welcome.

Caml code listing inside LaTeX


Philippe Wang announced:
If ever you are interested in putting some caml code inside your latex 
document, *without* using verbatim environment or listings package, 

the online tool :  (*) 

takes some caml code and returns LaTeX code. 

The applied treatments are : 
- colors 
- nested comments (even with strings such as "*)" inside) are detected 
- based on LaTeX macros such as 
     \DeclareTextSymbol{\BS}{T1}{92} % backslash 
- the code is put in a tabular environment 

Well, it's very small : 300 lines of code for the moment (about 230 
lines of ocamllex and 30 lines of ocaml...). 

It could have certainly been written in camlp4 or in latex, but well, 
they are not (yet) my cup of tea. 

Hopefully, it will be released under a free license next month (if you 
are interested in this program, which license do you want ?) 

The main goals are : 
- no use of verbatim, so that it can be used with beamer without the 
[fragile] option 
- no use of the listings package (because it don't like it) 

It certainly contains bugs, it was never proved or certified, and 
probably never will be...


  Philippe Wang 

(*) I used php because cgi in pure caml is very complicated on the 
hosting server



Eric Stokes announced:
Announcing graph, a utility to print a pretty graph of a time series   
in an ansi terminal. 

its in godi :-)

Using folding to read the cwn in vim 6+

Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater).

:set foldmethod=expr
:set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'&lt;1':1

If you know of a better way, please let me know.

Old cwn

If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.

Alan Schmitt