Previous week Up Next week

Hello

Here is the latest Caml Weekly News, for the week of August 30 to September 06, 2011.

  1. Ocaml and the Fragile Base Class Problem
  2. Jane street's core (et al.) post-hurricane code release
  3. Esterel Technologies recrute un Ingénieur en développement Ocaml
  4. MediaWiki welcomes OCaml coders & reviewers - help Wikipedia display math better
  5. Conditionally boxed 32 bit integers?
  6. ocaml munin plugin example
  7. Job offer: OCaml research engineer
  8. Other Caml News

Ocaml and the Fragile Base Class Problem

Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-08/msg00245.html

Continuing the thread from last week, Alain Frisch replied to Jacques Garrigue:
> If you want just to structure your program, modules are better in most cases.
> There are still situations where classes are stronger than modules for 
> structuring:
> * when you have a default for some operation, but want to be able to change it
> * when you want to mix components, using multiple inheritance and virtual 
> methods and instance variables

I second that. We are moving some parts of our code base to a mixin
style implemented with multiple inheritance, virtual methods,
constraints, very rare overridding (and no instance variables). This
results in drastic reduction of code size compared to our previous
approach where code sharing between components was implemented with
simple function calls. The code is also easier to evolve.

We create objects (without state) to represent bags of properties
computed from parameters; each method represents a property. An object
is created by assembling reusable mixins (inheritance) and
implementing remaining virtual methods. Once the object is created, we
observe a few properties and throw the object away. In effect, we use
objects to describe purely functional computation graphs, with
reusable sub-graphs. (Most methods don't take argument; in order to
avoid repeated evaluation, we have a special hack which rewrites an
object's method table so as to give its methods a lazy behavior.)

The nice thing with this approach is that the object layer does all
the plumbing automatically. Combining several reusable components does
not require to pass data around from one component to another
explicitly. The old style with functions required to pass many
arguments, deconstruct the result (a component typically computes
several things), organize reusable components to avoid mutual
recursions, and define many data types (records to represent the
result of components). In some cases, a large amount of the code was
caused by such plumbing.

> Also, for various reasons, objects are not beginner friendly.
> I think the main problem is that they don't fit that well with type inference:
> both subtyping and polymorphic methods require explicit type annotations.

Time to advertise the implicit-subtyping branch?
      
Jacques Garrigue then replied:
Indeed the implicit-subtyping branch helps: if the compiler knows all
the types, it doesn't force you to write a coercion by hand.  On the
other hand, this is only a partial solution, as my comment was on the
lack of principality: you still need type annotations in many cases.
Constraint-based type inference might recover this principality, but
since the types inferred get even worse than with structural object
types, I'm afraid this is not really practical. (It might work better
with nominal subtyping.)
      

Jane street's core (et al.) post-hurricane code release

Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-09/msg00002.html

Till Varoquaux announced:
This release comes right after an earthquake and a hurricane so you
know this is going to be strong stuff!
This is our latest and greatest release of Jane street Core and
supporting libraries. For this release we've decided to move towards a
versioning scheme that is more coherent to our internal system so
everything is version 107.01.
With this release Sexplib Typeconv and Bin-prot are no longer
included. This is because we've merged back with Markus's version and
now release them from ocamlforge. They are packaged with oasis thus
bringing you the easiest to build, most portable release yet.
Sexplib and Bin-prot have had version bumps to fix compatibility
issues found while packaging Core. You should grab the latest version
while they are hot at:

_Sexplib (7.0.2) : https://forge.ocamlcore.org/projects/sexplib/
_Bin-prot (2.0.3): https://forge.ocamlcore.org/projects/bin-prot/
This release of bin-prot also includes contributions by Stéphane
Glondu to make it portable on all the architectures that debian is
compiled for. Thank you Stéphane!

All the other libraries are download-able from our own webpage
(http://ocaml.janestreet.com/?q=node/13)
The released libraries now all come with a [doc] build target that
extracts the ocamldoc HTML documentation. This documentation can also
be browsed online on our website.

_Fieldslib(107.01): Just a version bump
_Core(107.01): Core's support for Timezones has been improved. The
effort to provide a coherent,typesafe approach to programming carries
on with new types and module to deal with identifiers, ip host/port
couple etc...
_Core_extended(107.01):
  New wrapper for Posix_clocks.
More function to handle backward and forward compatibility in sexp
Sexp_extended.
[Types] is a module used to do type runtime introspection of ocaml
values (by using an universal value).

New in this release:

_Variantslib(107.01): A syntax extension to scaffold constructor
functions and accessors automatically from variant type definitions.
_Patdiff(107.01): Patdiff is a nifty diffing code utility that
generates diffs designed to be read by humans and not computers. It
uses the patience-diff algorithm to do inter-line and intra-line and
diffs.
      

Esterel Technologies recrute un Ingénieur en développement Ocaml

Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-09/msg00010.html

Amandine ROY announced (in French only):
Esterel Technologies recherche un ingénieur en développement OCaml
pour compléter son équipe Recherche & Développement.
Ce poste est à pourvoir sur notre site de Toulouse (31) ou d'Elancourt (78). 

Vous trouverez ci-après le lien internet vers la description du poste : 
http://www.esterel-technologies.com/company/jobs/france-toulouse 

Si vous êtes intéressé, contactez moi ! ou si vous connaissez une
personne susceptible de l'être, transférez-lui mon email.
      

MediaWiki welcomes OCaml coders & reviewers - help Wikipedia display math better

Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-09/msg00015.html

Sumana Harihareswara announced:
MediaWiki, the software that Wikipedia runs on, is mostly in PHP.  But
we would love some assistance on code review on our Math system, which
uses OCaml.  The Math extension provides support for rendering
mathematical formulas on-wiki via texvc.  Anyone interested in taking a
look at the existing code and critiquing or improving it?  We would love
code review and help getting some OCaml unit testing on that extension.

The extension: http://www.mediawiki.org/wiki/Extension:Math

Pending patches that need review:
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/tag/math  You can
click on a revision number to get the code review page, where you can
comment.  The ones that are marked "new" are pending; the ones that have
been marked "ok" have been officially approved.

Mailing list thread about needing OCaml unit testing:
http://lists.wikimedia.org/pipermail/wikitech-l/2011-August/054909.html

MediaWiki developers hang out in the #mediawiki FreeNode IRC channel and
in the wikitech-l mailing list,
https://lists.wikimedia.org/mailman/listinfo/wikitech-l.
      

Conditionally boxed 32 bit integers?

Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-09/msg00028.html

John Carr asked:
I am working with a file format the contains 32 bit integers.
I need to use int32 on 32 bit systems.  I would like to use plain
integers, unboxed and with native machine operations, on 64 bit
systems.

Is there any way to convince ocamlopt to choose between int and
int32 representations _at compile time_?

I could use first class modules to select implementations at
runtime, which is not worth the code complexity and still
requires an indirect function call to add numbers.  I could
conditionally compile different files depending on word size,
which strikes me as an ugly and fragile solution.

I want to be able to write "int32" and have that be compiled
like an ordinary integer type if 32 bits and tag fit into a
word, and as a boxed type otherwise.  (The compiler could
mask off excess precision if desired.)  Is there a reason ocaml
can't provide this?

Another implementation would have each instance of an int32 or
int64 be boxed or not depending on whether the value fits into
a word.  I don't know whether this would be faster or slower in
practice.  There is a tradeoff between allocations and
conditional branches.
      
Hezekiah M. Carty replied:
You may be able to use ideas/implementation from the Int63 module:

http://people.redhat.com/~rjones/virt-df/html/Int63.html
or
http://www.janestreet.com/ocaml/janestreet-ocamldocs/core/Int63.html

The Int63 module uses int internally on 64bit OCaml installations and
Int64.t internally on 32bit OCaml installations.  I am not familiar
with the details but it may be adaptable to your needs.
      
Richard W.M.Jones also replied:
The Bitstring module could use this too ...
      
Gerd Stolpmann also replied:
The Netnumber module of Ocamlnet actually does this:

https://godirepo.camlcity.org/svn/lib-ocamlnet2/trunk/code/src/netstring/netnumber.mli
https://godirepo.camlcity.org/svn/lib-ocamlnet2/trunk/code/src/netstring/netnumber.mlp

Netnumber is fairly standalone, so you could just copy it to your
project if you don't want all of Ocamlnet.
      
rixed asked and John Carr replied:
> I suppose you don't want to use any kind of preprocessor, do you ?

I'd rather not preprocess (or compile alternate files).  Both the
netnumber and core implementations use a preprocessor.

Preprocessor-based solutions have two problems.  One is the extra
compilation step.  Another is bitrot in the unused case.

I think it was Plan 9 where the documentation said don't use the
C preprocessor, our compiler does the right thing with if (false).
In ocaml what I'd like to say is

        module Int : sig
          type t
          val add : t -> t -> t
          ...
        end;
        module Intfast : Int = struct type t = int ... end
        module Int = if sixtyfour then Int end else Int32

with the understanding that the expression sixtyfour is evaluated
at compile time.

Here is some similar code using 3.12 syntax:

        module type M = sig type t val add : t -> t -> t val of_int : int -> 
t end;;
        module Int : M = struct type t = int let add = (+) let of_int x = x 
end;;
        module M = (val (if Sys.word_size = 64 then (module Int : M) else 
(module Int32 : M)) : M);;

        let f x = M.add (M.of_int x) (M.of_int 1)

If the test (Sys.word_size = 64) is replaced by (true) this does what
I want.  The compiler looks through the packing and unpacking and
sees the module Int.  The body of function f compiles to a machine add
instruction.

Ocamlopt does not evaluate (Sys.word_size = 64) at compile time
because Sys.word_size is initialized at runtime.  See sys.ml line 26
and run objinfo on sys.cmx.

INRIA developers, is it easy to add an intrinsic so we can write

        extern word_size : int = "%caml_word_size"

in sys.ml?  If sys.cmx has a constant definition, ocamlopt should do
constant folding on conditional expressions testing Sys.word_size.

If I want to do conditional compilation, can ocamlbuild be taught
"compile file a.ml as module X on 32 bit systems and module b.ml as
module X on 64 bit systems"?
      
Later on, John Carr added:
I found a simpler way to make Sys.word_size be a compile time constant.
See patch at end.  Technically this is preprocessing, which I wanted to
avoid, but it's not preprocessing in my code.

> INRIA developers, is it easy to add an intrinsic so we can write
> 
>       extern word_size : int = "%caml_word_size"
> 
> in sys.ml?  If sys.cmx has a constant definition, ocamlopt should do
> constant folding on conditional expressions testing Sys.word_size.


diff -rc /tmp/ocaml-3.12.1/stdlib/Makefile.shared ./stdlib/Makefile.shared
*** /tmp/ocaml-3.12.1/stdlib/Makefile.shared    Fri May 21 07:28:21 2010
--- ./stdlib/Makefile.shared    Mon Sep  5 17:39:14 2011
***************
*** 49,56 ****
  stdlib.cmxa: $(OBJS:.cmo=.cmx)
        $(CAMLOPT) -a -o stdlib.cmxa $(OBJS:.cmo=.cmx)
  
! sys.ml: sys.mlp ../VERSION
!       sed -e "s|%%VERSION%%|`sed -e 1q ../VERSION`|" sys.mlp >sys.ml
  
  clean::
        rm -f sys.ml
--- 49,57 ----
  stdlib.cmxa: $(OBJS:.cmo=.cmx)
        $(CAMLOPT) -a -o stdlib.cmxa $(OBJS:.cmo=.cmx)
  
! sys.ml: sys.mlp ../VERSION ../config/m.h
!       ws=`sed -n -e 's/^#define ARCH_SIXTYFOUR/64/p' -e 's/^#undef 
ARCH_SIXTYFOUR/32/p' ../config/m.h`; \
!       sed -e "s|%%VERSION%%|`sed -e 1q ../VERSION`|" -e 
"s|%%WORD_SIZE%%|$$ws|" sys.mlp >sys.ml
  
  clean::
        rm -f sys.ml
diff -rc /tmp/ocaml-3.12.1/stdlib/sys.mlp ./stdlib/sys.mlp
*** /tmp/ocaml-3.12.1/stdlib/sys.mlp    Mon Feb 26 09:21:57 2007
--- ./stdlib/sys.mlp    Mon Sep  5 17:35:33 2011
***************
*** 23,29 ****
  external get_argv: unit -> string * string array = "caml_sys_get_argv"
  
  let (executable_name, argv) = get_argv()
! let (os_type, word_size) = get_config()
  let max_array_length = (1 lsl (word_size - 10)) - 1;;
  let max_string_length = word_size / 8 * max_array_length - 1;;
  
--- 23,30 ----
  external get_argv: unit -> string * string array = "caml_sys_get_argv"
  
  let (executable_name, argv) = get_argv()
! let (os_type, _) = get_config()
! let word_size = %%WORD_SIZE%%;;
  let max_array_length = (1 lsl (word_size - 10)) - 1;;
  let max_string_length = word_size / 8 * max_array_length - 1;;
      
Fabrice Le Fessant then said:
I think the (old) reason of the way Sys.word_size is implemented is that
the same code can run both on 32 bits and 64 bits, when compiled to
bytecode. But of course, I see no reason why such a primitive could not
be added, with different compilation schemes for asm (it would be hard
coded) and bytecode (it would continue to call the runtime function).
      

ocaml munin plugin example

Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-09/msg00041.html

Mihamina Rakotomandimby announced:
A quick and dirty Munin plugin I currently use to monitor my traffic consumption: http://is.gd/2tUKFM 

I have a limited plan (3GB) on an USB 3G stick (ppp0 interface), better to monitor it. 

I store the ppp0 RX and TX traffic in a SQLite3 database in a 5 min basis with a cron: 

*/5 *  *   *   * \
    sqlite3 /home/mihamina/accouting \
   "INSERT INTO ifconfig VALUES(NULL, DATETIME('NOW')  \
     $(/sbin/ifconfig ppp0 | sed 's/:/ /g' \
   | awk '/RX bytes/{print ",", $3, "," ,$8, ")"}')"

Need to store the counters in a persistent way because when deconnecting/reconnecting, counters reset. 

I realized later there was an easier way by parsing /proc/net/dev instead of parsing ifconfig output. I'll switch to that later. 

I'll blog it later too... :-)
      

Job offer: OCaml research engineer

Archive: https://sympa-roc.inria.fr/wws/arc/caml-list/2011-09/msg00042.html

Fabrice Le Fessant announced:
Position available: Ocaml research engineer

INRIA Saclay [1] is hiring a Research Engineer with good skills in
OCaml programming for 1 year.

Keywords: OCaml, development tools, compilation, Java interoperability

Task: The engineer will join a development team, focused on
programming an OCaml development platform, as member of the Feder
european project DORM (Derived Object Repository Manager). The work
will take place either in INRIA Saclay [1], or in the new research
center on free/open source software (IRILL) [2] in Paris.

He will participate in the development of various components of
the development platform, in particular tools for :
- the management of OCaml projects
- the compilation of these projects
- the interaction with the repository manager
- the interoperability with Java world tools

About INRIA Saclay:

The host team at INRIA Saclay [1] focuses on the study and improvement
of the OCaml language, and the development of a programming platform
for OCaml, in partnership with the OCamlPro company. The plateform is
composed of multiple development tools, such as code generators,
refactoring tools, navigation tools, etc. all directly available from
the code editor (Emacs, Eclipse) as an IDE.

About the IRILL:

The IRILL is a new international research centre on free/open source
software located in Paris. IRILL's objective is to become a reference
center for the research and development of stable and reliable free
software. By hosting development projects, IRILL also acts as an
observatory and experimental centre for transfer using free software.

Required skills:

- Expertise in OCaml programming
- Knowledge of Unix development standards
- Engineer or PhD degree (master may be sufficient under conditions)

Contact:
Fabrice Le Fessant
Fabrice.Le_Fessant AT inria.fr

[1] http://www.inria.fr/centre/saclay
[2] http://www.irill.org/
[3] http://www.ocamlpro.com/
      

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 http://planet.ocamlcore.org/.

Arrrgghh writing GUI programs is tedious:
  http://rwmj.wordpress.com/2011/09/04/arrrgghh-writing-gui-programs-is-tedious/

One Year On:
  http://gaiustech.wordpress.com/2011/09/04/one-year-on/

A functional/logic programming tidbit in Mercury:
  http://blog.dbpatterson.com/post/9762527668

Polydroml:
  https://forge.ocamlcore.org/projects/polydroml/

Programming Decisions with Coq's Sumbools:
  http://seb.mondet.org/blog/post/coqtests-02-sumbools.html

OCamlnet 3.4:
  http://caml.inria.fr/cgi-bin/hump.cgi?contrib=402
      

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