Previous week Up Next week


Here is the latest Caml Weekly News, for the week of November 20 to 27, 2012.

  1. Poll results of OASIS, package manager and misc.
  2. open faculty position in Big Data at Wright State University
  3. how to wrap a command line call correctly?
  4. Monad Library?
  5. RPM's for OCaml 4.00.1 and associated libs for Mageia 2
  6. opass - encrypted password db
  7. Multithreaded https requests in ocamlnet netclient
  8. New group: Pragmatic functional programming research
  9. Other Caml News

Poll results of OASIS, package manager and misc.


Continuing the thread from last week, Sylvain Le Gall said:
After searching a bit here is the right link:

This one doesn't require authorization, please use it.

open faculty position in Big Data at Wright State University


Pascal Hitzler announced:
We are seeking a faculty member in Big Data. Appointment at any rank
is possible (Assistant, Associate, or full Professor).

Particular areas of interest include, but are not limited to, data
management and lifecycle, data analytics, data visualization, data
fusion and integration, semantics and ontologies, social and sensor
Web, biomedical and health informatics.

Outstanding applicants with a high potential for collaborations with
existing strengths of the department and the Kno.e.sis Center are
particularly welcome to apply. Outstanding applicants specializing in
other emerging research areas are also welcome to apply.

For more information:

- or email me.

how to wrap a command line call correctly?


Florent Monnier asked and Malcolm Matalka replied:
> I would like to know how to wrap a command line call correctly?
> I particular keep the same order of the output messages for stderr and
> stdout correctly, how to handle the cases when there is something on
> stdin or not, etc.

You can use Jane St Async or Lwt, but your application needs to work
within that context for the best results (although I'm sure you can
do something clever here). Otherwise you probably need to use the Unix
model or similar and write your own little select loop. Or use threads
Gerd Stolpmann also replied:
There is no way to keep the order of output messages, except you
assign stdout and stderr to the same descriptor.

Otherwise, the Shell library included in Ocamlnet is your friend:

Especially, it can also be used in a synchronous environment (no need
to tie yourself to Lwt), but async usage is also possible.

Shell takes advantage of the fast posix_spawn calls so far provided by
the OS (e.g. on Linux and OS X), which means a significant speed
advantage compare to fork+exec.

Monad Library?


Chris Yocum asked:
I was looking into using Monads in my programs but I am slightly at a
loss as to what library is in general use. There is pa_monad but that
seems to be a ocamlp4 exention and not a library. There is but that doesn't seem to be
in opam or in godi so I am unsure as to its status.

Does anyone have any suggestion for a well supported monad library for
Wojciech Meyer replied:
pa_monad is really useful and nice, I think the updated library is
available as pa_monad_custom OPAM package.

> Does anyone have any suggestion for a well supported monad library for
> Ocaml?

First I would need to find an answer what do you mean by a monad library.

Monads is a general abstraction with a very simple interface. so they
don't require library as such.

However I agree it would be good to have some library that provides a
monadic interface to some common functionality found maybe in std
libraries, also some way of composing monads would be good having
monad transformers along. Batteries included offer monadic interface
to some common data types like list, bool, option.

You could look at Xavier Leroy's lectures here [1] to see the
excellent examples of using monads in OCaml.

For somewhat advanced type system trickery to use generic interface
for monads you can look at this excellent post [2].


David House also replied:
The Core library [1] has a good monad library that gets used in
basically every single Jane Street program (and notably inside async).
Among its features are:

* Module types for monads with one or two type parameters

* Functors to make modules satisfying those signatures given just bind +

* "Infix" submodules which one can locally open ("let open
Option.Monad_infix in") in order to temporarily work inside another
monad -- very useful.

It notably does *not* feature a syntax extension to make monadic
computations look pretty. You must write out the binds and returns
yourself. To be honest, the reason for this is mostly history, but we
actually have some anecdotal evidence now that writing in the explicit
style makes things easier to understand for authors and readers of

He then added:
Of, and of course it features instances for Option.t, Result.t,
Or_error.t, List.t and all the other standard types inside core!        
Michał Kurcewicz also replied:
If Core is too complex for you then you may take a look at spotlib - a
small and elegant library written by Jun Furuse:

I use it together with pa_monad_custom for all my monad needs.
Chris Yocum then asked and Gabriel Scherer replied:
> So basically from what I understand this is kind of like a StateMonad.
> It seems to me that the state monad (hiding state in the type system)
> would be a large boon.
> So, for instance,
> module type MONAD =
> sig
> type 'a t
> val return : 'a -> 'a t
> val bind : 'a t -> ('a -> 'b t) -> 'b t
> end
> module StateMonad : MONAD =
> struct
> type 'a t = Store of 'a
> let return x = Store(x)
> let bind s f =
> match s with
> | Store(x) -> f x
> let access = function Store(x) -> x
> end
> This is a very, very basic implementation of a state monad?

No it's not. What you implemented is the identity monad (type 'a t =
'a, only wrapped under a constructor) that doesn't emulate any effect
at all. The state monad (over some fixed "state" type, for example
"int" if your state is an integer) would use a definition of the form
(untested code):

module StateMonad : sig
include MONAD
type state
val get : state t
val set : state -> unit t
val run : state -> 'a t -> state * 'a
end = struct
type state
type 'a t = state -> state * 'a

You should probably try to wrap your head around monads by reading
documentation and implementing some of them yourself *before* looking
for a third-party library that provide monadic facilities.

Wojciech gave excellent references about monads. If you want something
maybe more easy-going and still in OCaml, you could also have a look
at Brian Hurt's "a Monad Tutorial for OCaml":

Of course, most of the literature on monads uses Haskell, the language
in which they became popular first. It's actually quite easy to read
Haskell code if you're already familiar with OCaml, so those documents
should be accessible as well. Of course I don't recommend that if
you're not already comfortable with OCaml semantics (... or

RPM's for OCaml 4.00.1 and associated libs for Mageia 2


Florent Monnier announced:
Here are some RPM's for OCaml 4.00.1 and associated libs for Mageia 2:
(Mageia 2 provides ocaml 3.12.1)

(of course uninstall ocaml and every ocaml libs before)

These RPM's were built for Mageia 2 from the last packages versions in
Cauldron (the development version of Mageia).
Mageia is not a rolling release, so these .rpm won't be provided in Mageia 2.

These .rpm will probably be the ones for Mageia 3 when it will be
released if no problem are found in it.
So please test these and report any problem or success.

If you don't have time to fill a bug, you can just send an email to me
and malo (his email is in cc).

I've not generated the complete set that's in svn:
Just ask if you're interested by an other one.

Also if there are some "must have" that are not yet in Mageia, please
also just ask!

opass - encrypted password db


Malcolm Matalka announced:
This week I hacked up a little local encrypted password db in Ocaml and
wanted to share. It's a pretty small amount of code, and just a first
iteration, so expect it to be messy. It makes use of the Core library,
specifically it stores the DB in sexpr's, it uses the (deprecated)
command line interface, and the Shell module quite a bit. Hopefully
it's a useful tool and it's small size is helpful for those picking up

Multithreaded https requests in ocamlnet netclient


Mike Lin asked and Gerd Stolpmann replied:
> I'm trying to find the right incantations to make parallel https
> requests from multiple threads using Http_client. (I know the library
> is capable of multiple requests from one thread -- I have other strong
> reasons to use multithreading.)
> This program generally segfaults for me at some random point during
> the 10 requests. Compiled as in the comment in line 2 (ubuntu quantal,
> libocamlnet-ocaml-dev 3.5.1, ocaml 3.12.1).
> Permutations attempted:
> 1) Change https to http in google URL -- works as expected
> 2) Serialize requests by uncommenting line 35 -- works as expected
> 3) Move invocations of Ssl.init, Ssl.create_context,
> HTTPS.https_transport_channel_type in and out of fresh_pipeline (which
> runs in the worker threads) -- no help

I can confirm the problem, but I'm not able to track it down.

First of all, I'm quite sure that you cannot share SSL contexts
between threads. But even if I fix this, I get crashes - usually early
during SSL_connect.

I'm wondering whether ocaml-ssl initializes openssl correctly for
multi-threading. In my version of openssl the prototype is

int CRYPTO_THREADID_set_callback(void (*threadid_func)(CRYPTO_THREADID

but in ocaml-ssl the CRYPTO_THREADID pointer is ignored (it assumes
void here). So, maybe this is the reason. I currently don't have time
to follow this idea.

If everything fails, there is a way to use Netclient in threaded
applications so that only one thread is doing the networking stuff,
see this example:

As Netclient is event-driven, the requests are processed in parallel
(with one exception, though: DNS lookups are synchronous, but this can
be worked around, as the DNS lookup function is settable in

New group: Pragmatic functional programming research


Jon Harrop announced:
I've started a new Google Group to discuss the practical use of former
research around functional programming including issues such as designing
purely functional data structures to leverage mainstream virtual machines
(JVM and CLR) and garbage collectors, wrapping mainstream libraries (e.g.
Windows Presentation Foundation) to improve productivity from modern
functional languages and so on. Please join us here:!forum/pragmatic-functional-programming-research

Other Caml News

From the ocamlcore planet blog:
Thanks to Alp Mestan, we now include in the Caml Weekly News the links to the
recent posts from the ocamlcore planet blog at

Type-based selection of label and constructors:

Stog 0.4:

Xtmpl 0.4:

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