Previous week Up Next week


Here is the latest Caml Weekly News, for the week of October 27 to November 03, 2009.

  1. forbidden construct as right hand side of "let rec"
  2. ocaml-gettext v0.3.3
  3. Other Caml News

forbidden construct as right hand side of "let rec"


Mathias Kende and Lukasz Stafiniak asked, and Xavier Leroy answered:
Mathias Kende wrote:
> I need to write something like this :
>       let f f i = if i = 0 then 1 else i * f (i - 1)
>       let rec g = f g
> Of course the compiler won't let me write it (even if the OCaml type
> system is happy):
>       "This kind of expression is not allowed as right-hand side of `let rec'"
In general, the best thing to do in this case is to switch to lazy

# let f f i = if i = 0 then 1 else i * Lazy.force f (i-1);;
val f : (int -> int) Lazy.t -> int -> int = <fun>
# let rec g' = lazy (f g');;
val g' : (int -> int) Lazy.t = <lazy>
# let g = Lazy.force g';;
val g : int -> int = <fun>
# g 10;;
- : int = 3628800

Lukasz Stafiniak wrote:
> While we are at it, what is the best way to convert a "straight" list
> into a cyclic list?
> i.e. convert
> let l = a::b::[]
> into
> let rec l = a::b::l
> (for arbitrary length lists). (The answer I recall from the archives
> was using Obj.magic to mutate the [] in the original list).

Obj.magic is not part of the OCaml language :-)

Again, you can do that just fine using lazy lists instead of lists:

type 'a lazylist = 'a lazylist_content Lazy.t
and 'a lazylist_content = Nil | Cons of 'a * 'a lazylist

ocaml-gettext v0.3.3


Sylvain Le Gall announced:
ocaml-gettext is a library that enables string translation in OCaml. The
API is based on GNU gettext. It comes with a tool to extract strings
which need to be translated from OCaml source files.

This enables OCaml program to output string in the native language of
the user, if a corresponding translation file of the English strings is

v 0.3.3 is a bug fix release:
* compatible with ocaml-fileutils 0.4.0
* more static type-check of format string


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

OCaml-gettext 0.3.3:

It’s coming:

Liquidsoap 0.9.2 is out !:

BlackBerry OS 5.0 and the Storm:

XML or S-expressions?:

ocamlbuild example repository:

New HLVM GC and LLVM 2.6 support:

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