Previous week Up Next week


Here is the latest Caml Weekly News, for the week of July 15 to 22, 2008.

As I will be moving from Italy to France next week, there will not be a CWN. I will try the week after that if I have internet access. Good vacations to all!

  1. Profiling ocaml using gprof
  2. ocaml-bitstring 1.9.6 (formerly known as ocaml-bitmatch)
  3. Position
  4. "OCaml Developers" group just created on LinkedIn
  5. NW Functional Programming Interest Group
  6. Name of currently executing function
  7. Commercial Users of Functional Programming Workshop Call for Participation
  8. Understanding monads

Profiling ocaml using gprof


Arthur Chan asked and Richard Jones answered:
> Is gprof better for profiling ocaml than ocaml's own profilers?

They are slightly different.  I use 'gprof' all the time because I
tend to only use natively compiled executables.  'gprof' is the
ordinary GNU profiling tool that tells you which function is being run
most often and some limited information about the call path into that
function.  It's pretty useful for simple profiling where you're
looking for obvious problems.

'ocamlprof' is a bit different.  Last time I used it [which was a few
years ago, so maybe it's different now], it only worked on bytecode.
It outputs your original code with annotations telling you how often
each expression was run.  So this isn't time taken (each expression
can take a different amount of time to execute, and this time isn't
shown), but how often a particular path through the code is taken.

> How would you go about figuring out that that particular function stub is
> string concat?
> 'camlPervasives__$5e_136'.

In 'gprof' there's a simple name mangling used to map OCaml function
names to assembler symbols.  Once you understand it, you'll find it
easy to follow.  First of all note that OCaml function names aren't
unique, eg in the following code:

 let f () = printf "this is the first f()\n"
 let f () = printf "this is the second f()\n"; f () ;;

 f ()

The assembler symbol is:

 "caml" ^ Modulename ^ "__" ^ functionname ^ "_" ^ uniquenumber

'uniquenumber' is just a counter added to function names by the
compiler to make sure that functions which have the same name will
have different symbols.

So when I compiled the code above in a file called '' (hence a
module called Test), in my case I ended up with two symbols called:


where '77' and '78' are arbitrary.  You can check this by looking at
the assembler output from the compiler (ocamlopt -S).

If a function name contains an operator symbol (eg. (^) ) then a $xx
hex code is used.

I guess in theory one could write an OCaml symbol filter, similar to
c++filt []

ocaml-bitstring 1.9.6 (formerly known as ocaml-bitmatch)


Richard Jones announced:
I'm please to announce version 1.9.6 of ocaml-bitstring (formerly
known as ocaml-bitmatch).  The home page has changed again, so please
update any bookmarks or links to point to the new home page here:

Version 1.9.6 features 'check()', 'bind()' and 'save_offset_to()'
qualifiers which give you much greater control over the matching
process.  For example:

 bitmatch packet with
 | { len  : 16  : check (len > 0), bind (len*8);
     data : len : string;
     crc  : 32  : check (crc_ok data crc), save_offset_to (crc_offset)
   } ->
   printf "length of data (in bits) = %d\n" len;
   printf "offset of CRC in packet (in bits) = %d\n" crc_offset

 | { _ } -> printf "bad packet\n"

We have also fixed some bugs, clarified the licensing everywhere (for
Debian), and improved the META file.



Ihsan Ecemis announced:
We are a fast-paced, VC-funded, Boston-based startup currently building our
flagship product targeted at the scientific community. We need a few sharp
minds to help us.

We are using OCaml in our core simulation technology. We are looking for
someone who is mathematically minded, has fun with his work, takes pride in
its quality, and learns quickly.

If facing the challenges of building cutting-edge technologies is your idea of
a good time, then you are going to love working with us. We are solving hard
problems and having a lot of fun doing it. Join us.

* 3+ years of experience in functional programming, preferably in OCaml
* Strong CS fundamentals

The best candidates will have experience with:
* Dealing with a large code base, complex data structures, and intricate
  control loops
* Scalability and performance issues
* Simulations of complex systems
* Conducting research on basic algorithms, mathematics, agent-based models

To apply for this position, submit your resume to

"OCaml Developers" group just created on LinkedIn


Stefano Zacchiroli announced:
In case you are in the LinkedIn professional network, you might be interested
in knowing that I've just created an OCaml group there:
It is called OCaml Developers and it is intended to provide yet another way
for the community of OCaml programmers to advertise themselves to the
professional world.

I was surprised by the fact there were no professional group related to OCaml
there, and that's why I created one. The only group I found mentioning OCaml
was a very narrow one about the usage of functional programming for financial
purposes, probably all Jane St employees are members

Feel free to join the new group. Also, if you want to spare the duty of
checking/accepting new people into the group drop me a line, you will be more
than welcome!

NW Functional Programming Interest Group


Greg Meredith announced:
This is just a friendly reminder to Northwest functionally minded folks that
this month's meeting is to be held

The Seattle Public Library
5009 Roosevelt Way N.E.
Seattle, WA 98105

from 18.30 - 19:45 on July 23rd. 

We'll be getting a demo of a scala-lift-based application that compiles a
graphical rendition of functional expressions into expressions in a functional

Hope to see you there.

Name of currently executing function


Continuing the thread from last week, Dave Benjamin announced:
Thanks again for your help, blue storm. I condensed this technique into a
simple example for PLEAC, which I just committed here:

It allows you to write this:

(* An example named function. *)
let test_function () =
 let str = "Hello, world!" in
 let num = 42 in
 LOG "str=\"%s\", num=%d" str num;
 print_endline "test complete"

(* Some code to run at the toplevel. *)
let () =
 LOG "not in a function";
 test_function ()

And get the following output:

<toplevel>[]: not in a function
test_function[]: str="Hello, world!", num=42
test complete

Commercial Users of Functional Programming Workshop Call for Participation


Jim Grundy announced:
      Commercial Users of Functional Programming Workshop (CUFP) 2008

               Functional Programming As a Means, Not an End

                          Call for Participation

                           Sponsored by SIGPLAN
                         Co-located with ICFP 2008

                             26 September 2008
                             Victoria, Canada

                  Registration opens in late July through

  Functional languages have been under academic development for over 25
  years, and remain fertile ground for programming language research.
  Recently, however, developers in industrial, governmental, and open
  source projects have begun to use functional programming successfully
  in practical applications. In these settings, functional programming
  has often provided dramatic leverage, including whole new ways of
  thinking about the original problem.

  The goal of the CUFP workshop is to act as a voice for these users of
  functional programming. The workshop supports the increasing
  viability of functional programming in the commercial, governmental,
  and open-source space by providing a forum for professionals to share
  their experiences and ideas, whether those ideas are related to
  business, management, or engineering. The workshop is also designed
  to enable the formation and reinforcement of relationships that
  further the commercial use of functional programming. Providing user
  feedback to language designers and implementors is not a primary goal
  of the workshop, though it will be welcome if it occurs.


  CUFP 2008 will last a full day and feature a discussion session and
  the following presentations:

  Don Syme (Microsoft)
         Invited Presentation: Why Microsoft is Investing in Functional

  David Balaban (Amgen)
         Minimizing the Immune Response to Functional Programming at

  Francesco Cesarini (Erlang Training and Consulting)
         The Mobile Messaging Gateway, from Idea to Prototype to Launch
         in 12 months

  Jake Donham (Skydeck)
         From OCaml to Javascript at Skydeck

  Nick Gerakines (Yahoo)
         Developing Erlang at Yahoo

  Tom Hawkins (Eaton Corporation)
         Controlling Hybrid Vehicles with Haskell

  Bob Ippolito (Mochimedia)
         Ad Serving with Erlang

  Anil Madhavapeddy (Citrix)
         Xen and the art of OCaml

  Howard Mansell (Credit Suisse)
         Quantitative Finance in F#

  Jeff Polakow (Deutsche Bank)
         Is Haskell ready for everyday computing?

  David Pollak (Lift web framework)
         Buy a Feature: an adventure in immutability and Actors

  Gregory Wright (Antiope)
         Functions to Junctions: Ultra Low Power Chip Design With Some
         Help From Haskell

  There will be no published proceedings, as the meeting is intended to
  be more a discussion forum than a technical interchange.

  See for more information, including
  presentation abstracts and the most recent schedule information.

Program Committee

    * Lennart Augustsson <lennart(dot)augustsson(at)gmail(dot)com>
    * Matthias Blume <blume(at)tti-c(dot)org>
    * Adam Granicz <granicz(dot)adam(at)intellifactory(dot)com>
    * Jim Grundy(co-chair)<jim(dot)d(dot)grundy(at)intel(dot)com>
    * Andy Martin <akmartin(at)us(dot)ibm(dot)com>
    * Yaron Minsky <yminsky(at)janestcapital(dot)com>
    * Simon Peyton Jones(co-chair)<simonpj(at)microsoft(dot)com>
    * Ulf Wiger <ulf(dot)wiger(at)ericsson(dot)com>

  This will be the fifth CUFP; see CUFP 2004 CUFP 2005, CUFP 2006, and
  CUFP 2007 for information about the earlier meetings, including
  reports from attendees and video of the most recent talks.

Understanding monads


Paolo Donadeo asked and Till Crueger answered:
> I like functional programming, but monads [1] must be too little to be
> grabbed by my mind. This time the interest in monads was aroused by
> the interesting article of David Teller, Arnaud Spiwack and Till
> Varoquaux [2] about the error monad, but for using the library they
> wrote I need at least some knowledge about monads and the do-notation.

it might take a while, but it's worth the effort... It took me some time
to get the concept as well. Don't worry it doesn't have to do with your IQ.

> I ask you all: can anyone make me a practical example, something
> involving strings, files, the network, an image or sound processing
> algorithm, something vaguely real? Not abstract mathematical
> structures, beautiful algebraic properties and general statements,
> please: the net is full of such tutorials, especially Haskell fan
> sites ;-)

hmm, very informaly speaking, monads allow you to "wrap up" some other
value, or a set of those... Then of course there are lot's of way's to
wrap something up, so this is really abstract.

One good thing that helped me a lot, was to implement the monads myself in
OCaml, even though i hadn't understood them fully at that time. Try for
example to build your own I/O Monad and it will start to get more clearly
how it works.

> [1]

I suggest this one instead as a good starting point:

> [2]
Fabrice Marchant then said:
> I suggest this one instead as a good starting point:

Among the links appearing at the bottom of this document, this non
theoretical-one appears the coolest to understand for me. The "pure function
debugging" example allows simple OCaml experimentions :
Gabriel Kerneis answered the original question:
Xavier Leroy's lesson on monads [1] will certainly be too abstract for
you, but the accompanying Caml code [2] might help you to grasp the
concept. You will find there a lot of example of useful monads. You should
have read some tutorial before, though, not to get lost.

Another very concrete example is Lwt [3], a cooperative thread library
written in monadic style. Don't hesitate to follow the link, it's a
documentation targeted at programmers, without categorical issues and so
on. You will need to read a more general tutorial on monads then, to get
the general idea, but it could be a good starting point to "bind" and
"return" operators.


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