Previous week Up Next week

Hello

Here is the latest Caml Weekly News, for the week of August 21 to 28, 2007.

  1. ocaml-curses 1.0.1 released
  2. Vprint: a runtime value printer module
  3. pa_monad 1.2.0 - ported to Ocaml 3.10
  4. commands.getoutput () in ocaml?
  5. SF Bay Area Functional Programmers http://bayfp.org/
  6. Commercial users of functional programming 2007: programe is published, registration open

ocaml-curses 1.0.1 released

Archive: http://groups.google.com/group/fa.caml/browse_frm/thread/0cf93a231a66af4f/dc49a30460513a2c#dc49a30460513a2c

Richard Jones announced:
I am pleased to announce the second release of OCaml Curses, which is 
an OCaml binding to the curses / ncurses library. 

This version includes a Mac OS X build fix (Andres Varon) and contains 
multi-threaded work and additional coverage (Paul Pelzl). 

The project homepage is: http://www.nongnu.org/ocaml-tmk/ 
Releases: http://download.savannah.nongnu.org/releases/ocaml-tmk/ 

Mailing list: http://lists.nongnu.org/mailman/listinfo/ocaml-tmk-devel 

OCaml-curses is also included in Fedora 7/8, just enable the 
development repo and then do 
  yum install ocaml-curses ocaml-curses-devel
			

Vprint: a runtime value printer module

Archive: http://groups.google.com/group/fa.caml/browse_frm/thread/0d6b019a93ab22aa/1a9edb31bb2dc26a#1a9edb31bb2dc26a

Zheng Li announced:
In the spirit of "release early, release often", we therefore announce the 
first release of Vprint, a runtime value printer module for OCaml. Be warned, 
the module is extremely experimental at the moment, and the implementation is 
very hasty (I got the main idea yesterday when finalising my GSoc project and 
now it's here). So be ready to encounter stupid errors and even core dump, but 
do remember to send me a message about that so I can improve. Here is the 
introduction from README: 

DESCRIPTION 
=========== 

Vprint is a value printer module for OCaml. It prints any value at running time 
with a simple generic printer. It can be used for the following purposes: help 
debugging, inspect data representation, test type casting, runtime dispatch 
based on type representations and avoid writing pretty printers. 

  - Help debugging. 

    For rapid development reason, we don't want to write a printer/formatter 
    function for each data type. Moreover, even if we've got the printers for 
    each type, specifying printers to inspect the running time values, which 
    are usually the arbitrary combinations (tuple, list, variants, objects 
    etc.) of them, is still tedious. 

  - Inspect data representation 

    The module can shows you all kinds of data (of different types) that having 
    the same memory layout as a input data. 

  - Test type casting 

    By printing a value with the format of another type, it can help to test 
    whether a data can be safely cast to another type without actually doing 
    it. But be warned, the real casting can still fail even if the printing 
    successes. 

  - Runtime dispatch based on type representations 

    In the same spirit as above. 

  - Avoid writing pretty printers (TODO) 

    Without considering debugging, sometimes you still need to output the 
    values of some data type. If you don't care much about the format and just 
    want the result shew, then you probably don't have to write it by your own 
    now; if the OCaml toplevel printer is something you'd like, we're on the 
    way there, if given more time. 

FEATURES 
======== 

There are just two main functions "print" and "print_all" (and their 
output-to-string version "sprint" and "sprint_all") 

    val print: ?fmt:fmt -> 'a -> unit 
    val print_all: ?fmt:fmt -> 'a -> unit 

The "print" function can prints any data with a generic printer. However, it's 
well-known fact that OCaml runtime doesn't carry type information, so the 
output maybe too generic to read sometimes, e.g. the representation of list is 
something like a linked pairs. 

The implementation tries to inference the actual data type, however due to the 
theoretical limitation, there do exist many cases where the output is not 
satisfactory such as the list/pair example. And we don't believe it's 
appropriate to just choose a probable result based on probabilities, because 
misleading is even worse. (1, (2, (3, (4, (5, (6, 0)))))) is mostly likely to 
be a list, but not necessarily. 

In such cases, you can give more hints to the system by using the optional ~fmt 
parameters. The format of fmt is very close to type representation and supports 
combination, so it's quite easy to write (check example section). Besides it 
accepts the default arguments "__" (means "anything") and try its best to 
inference more information based on the less information being given, so you 
don't have to write every details. 

In such as sense, fmt can be used as a simpler formatter if you want to pretty 
print some values as output but is lazy to write complex formatter, just gives 
more specific fmt information if you want better effect. For now, we use rather 
simple string output function, but we'll definitely move to Format and build 
better output a la OCaml's toplevel output. 

You can also use "print" to do preliminary tests of type casting. By printing 
value x of type t with a fmt associated with type t', you get more confidence 
to cast x to type t', instead of making real casting and get core dump, here 
you only get a Fmt_Error exception. I believe you've been warned it's not 
definitive, but the point is that the function can help you to rule out a lot 
possibilities beforehand. 

In the same spirit, you can use the function to do runtime dispatch based on 
type representations (not types! it's like representation level duck 
typing). E.g, something like (not tested yet) 

    open Vprint 
    let o = input_value ch in 
    try ignore (sprint ~fmt:_s o); do_sth_to_o_as_string 
    with Fmt_Error _ -> 
      try ignore (sprint ~fmt:_f o); do_sth_to_o_as_float 
      with Fmt_Error _ -> 
        try ignore (sprint ~fmt:_l_ o); do_sth_to_o_as_list 
        with Fmt_Error _ -> ...... 

Finally, the "print_all" function can help you to inspect the representation of 
data, especially it lists all the data (of any types) that having the same 
memory representation as a value. For example, when you print a value with the 
default formatter: "print v", the output is so generic that won't satisfy 
you. Then you may wonder why the output is so generic? You can get the answer 
with "print_all v", then you'll see all kinds of values which having the same 
memory representation as your input "v", that's why the system won't be able to 
decide which one of them is the "v" hence print less meaningful result. 

INSTALL 
======= 

It's a simple module, just compile the source to cmo/cmx to use.  The source 
itself makes use of camlp4 (just for stream function), so compile it with 
option "-pp camlp4o". The result modules doesn't depend on camlp4, so you don't 
have to specify the camlp4 option when you make use of vprint. 

We also provide Makefile script with  the following command: make all, make 
install, make doc, make clean, make uninstall. 

Only tested under the following environment: Linux, OCaml 3.10.0, GNU Make 3.81. 

COPYRIGHT 
========= 

See file ./LICENCE 

EXAMPLE 
======= 

# open Vprint 

(* Some values are easy to identify *) 
# print ("asdf", [||], 3.14, [|1.01; 2.689|], 32l, 64L, 111n);; 
<"asdf", [||], 3.14, [|1.01; 2.689|], 32l, 64L, 111n> 

(* Some are difficult *) 
# print [1; 2; 3; 4];; 
<1', <2', <3', <4', 0'>>>> 

(* By giving it some type information, it's much better. 
   "_l __" means list of 'any, or use _l_ instead *) 
# print ~fmt:(_l __) [1; 2; 3; 4];; 
[1'; 2'; 3'; 4'] 

(* Why the number has a ' after it? *) 
# print 0;; 
0' 

(* Because there are several datum having this same representations we don't 
   know who is this guy currently *) 
# print_all 0;; 
[]       (* it could be empty list *) 
()       (* or the unit *) 
'^@'     (* or the char '^@" *) 
Con0     (* or the 1st no-param constructor of some variant type *) 
`Var0    (* or a no-param polymorphic variants with interval id = 1 *) 
0        (* or, at last, the int value 0! *) 

(* print_all can also take ~fmt arguments to restrict the choices, now the ' is 
   gone since 0 is the only choice as a int "_i" *) 
# print_all ~fmt:_i 0;; 
0 

(* Like the "'", "< >" is sequence whose type is yet to decide *) 
# print (3, 4);; 
<3', 4'> 
- : unit = () 
# print_all (3, 4);; 
[|'^C'; '^D'|]        (* array of 2 char, first is '^C", then '^D' *) 
{'^C'; '^D'}          (* record of 2 fields, both char *) 
('^C', '^D')          (* tuple of 2 char *) 
Con0# ('^C', '^D')    (* it's a variant type, here the value is its 1st 
                         with-param constructors with 2 char as params *) 
('^C', Con4)          (* tuple of char and variant whose value here is its 5th 
                         no-param constructor *) 
..... 
`Var3 4               (* a polymorphic variant type, its value here is a 
                         constructor with id=3 and taking int 4 as param *) 
[|3; 4|]              (* int array of two int *) 
..... 
(3, 4)                (* int tuple, our current input! *) 
.....                (* 50+ possibilities in total *) 

(* Really ? test *) 
# type t = A of char * char | B | C of t list;; 
# print (A ('\003', '\004'), [|3; 4|]);; 
<<3', 4'>, <3', 4'>> 

(* Make use of ~fmt, check manual for details, 
   be aware about the 'any: "_" "__" *) 

(* Print polymorphic variants *) 
# print ~fmt:(_l _'v_) [`How "vvv"; `Are 3.333; `You];; 
[`How "vvv"; `Are 3.333; `You] 

(* Print functions, code * environment *) 
# let k = 5;; 
# let rec f x = g x + k and g x = f x - k;; 
# print f; print g;; 
<fun#67404426 5'> 
<fun#67404440 5'> 

(* Print object, id * code * environment *) 
# print (object val x = 10 val y = 15 method get_xy = x + y end);; 
<obj#0/67328382 (10', 15')> 

(* Print forced lazy value *) 
# let l = lazy (8.28, "vvv") in let _ = Lazy.force l in print l;; 
lazy <8.28, "vvv"> 

(* fmt = 'any * int, *~ is the AND combinator, for collection *) 
# print ~fmt:(__ *~ _i) (3.14, 3);; 
<3.14, 3> 

(* fmt = 'v list and 'v = C' of char * char | C'' of 'any list 
   The // is OR combinator, for variants and polymorphic variants. 
   You can rewrite the variants part as _v (_c *~ _c) // _v _l_ *) 
# print ~fmt: (_l (_v (_c *~ _c // _l_)))  [A ('x', 'y'); C []];; 
[Con0# ('x', 'y'); Con1# []] 

(* fmt = int * 'any list * 'b array and 'b = 'any variant *) 
# print ~fmt:(_i *~ _l_ *~ _a _v_) (3, [3.14; 9.9], [|B; B|]);; 
<3, [3.14; 9.9], [|Con0; Con0|]> 

(* fmt = int array list list, the use of combinator @. (read as "OF" as in 
   "list of list of int array) can reduce "..))))..", otherwise we should 
   write it as (_l (_l (_a _i)))  *) 
# print ~fmt:(_l @._l @._a _i) [[[|1; 2|]; [|3; 4|]]];; 
[[[|1; 2|]; [|3; 4|]]] 

(* Anyway, it's really hard to describe all the details here, you'll have to 
   read the manual and play with it by yourself to understand. *)

http://www.pps.jussieu.fr/~li/software/index.html#vprint 
			

pa_monad 1.2.0 - ported to Ocaml 3.10

Archive: http://groups.google.com/group/fa.caml/browse_frm/thread/8e4dd3e15391c85e/dd6aca318b56284d#dd6aca318b56284d

Jacques, Lydia and Oleg:
We are pleased to announce a port of pa_monad to Ocaml 3.10.  As usual, 
all the files can be found at 
http://www.cas.mcmaster.ca/~carette/pa_monad 

We wish to thank Till Varoquaux for his help with this port.  We also 
thank all our users who prodded us gently for this update - we were 
warmly surprised by how many people used this extension.
			

commands.getoutput () in ocaml?

Archive: http://groups.google.com/group/fa.caml/browse_frm/thread/572edd459944a0ae/59fd380257a28918#59fd380257a28918

Luca de Alfaro asked and Dave Benjamin answered:
> I am looking for a quick way to do the equivalent of 
> s = commands.getoutput ("ls " + name + "*") 
> in Ocaml. 

I have translated many of the examples from the Perl Cookbook for the 
Process Management and Communication chapter of the OCaml PLEAC. This is 
one of the topics covered. 
http://pleac.sourceforge.net/pleac_ocaml/processmanagementetc.html
			

SF Bay Area Functional Programmers http://bayfp.org/

Archive: http://groups.google.com/group/fa.caml/browse_frm/thread/923e7ce68f54000b/3e3753511b8cc7b8#3e3753511b8cc7b8

Mike Wells announced:
I'd like to announce the formation of the Bay Area Functional 
Programmers group.  This group is for anyone using or interested in 
functional programming and functional programming languages, 
particularly strongly typed languages such as OCaml, Haskell, SML, etc. 

The first meeting will be Thursday, September 13th at 7:30pm somewhere 
in San Francisco.  Please join the mailing list at 
http://groups.google.com/group/bayfp 
and suggest a location. The 
initial meeting will be a casual pizza and beer get together, although 
going forward we'd like to also include speakers, reading and discussion 
of technical papers, and some hands on coding.  Future announcements and 
the location of the first meeting will be posted to the mailing list. 

More information will be available on the website: http://bayfp.org/. 

Many thanks to the NYFP meetup for the inspiration: 
http://lisp.meetup.com/59/.
			

Commercial users of functional programming 2007: programe is published, registration open

Archive: http://groups.google.com/group/fa.caml/browse_frm/thread/af509304b72bfb6e/f90b2886bc60d66c#f90b2886bc60d66c

Kathleen Fisher and Simon Peyton Jones announced:
The program for the 2007 Commercial Users of Functional Programming workshop 
is now published. 

        http://cufp.galois.com/ 

The workshop is co-located with ICFP, and will be held in Freiburg, Germany, 
on 4 October 2007.  We had a terrific response to our call for talks, and 
there are twelve (!) speakers describing commercial applications,  variously 
written in 
        Caml 
        Erlang 
        F# 
        Haskell 
        ML 
        Scheme 

The talks are informal, and there are no proceedings.  We'll just have fun 
learning about functional programming used to solve real problems.  Do come!
			

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
zM

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