Tooling is Awesome

Fri 16 October 2015

A quick note about my current OCaml setup, in my last project, Nunchaku.


First, I use Oasis to manage and build the project. It relies on OCamlbuild, but brings in several niceties:

  • automatic generation of configure and Makefile files.
  • it deals with sub-libraries, and the configure script can enable or disable the build of each sub-library.
  • it builds and runs my tests. Yay!


Oh dear. Merlin has improved my workflow with OCaml so much that I can't imagine working without it now. I can use it with Vim, but it also works for emacs users, so everyone is happy. The basics features I use are the ability to ask for the type of any expression (cursor on it, then \t), and the omni-completion of functions and modules in the same project or from (ocamlfind) libraries.

Incidentally, my vim setup includes a file ~/.vim/after/ftplugin/ocaml.vim containing

au filetype ocaml   :setlocal comments=sr:(*,m1:\ ,e:*)
au filetype ocaml   :nmap <leader>d :MerlinDestruct<CR>
au filetype ocaml   :nmap <leader>r :MerlinRename

au filetype ocaml   :syn sync maxlines=1500

The two middle lines are key bindings:

  • map \d to :MerlinDestruct, which decomposes variables into constructors in pattern matches.
  • map \r to :MerlinRename, to easily change the name of functions or variables (yes, it's better than a regex, because it knows about scoping).

Auto rebuild

The Makefile contains a target make watch that will loop forever, watching for changes in .ml files to recompile. It looks like this (careful, use tabs, as always with Makefiles):


    while find src/ -print0 | \
     xargs -0 inotifywait -e delete_self -e modify ;\
    do \
      echo "============ at `date` ==========" ; \
      make ; \


Well, that's it. I also use some other things, including of course Opam and opam.vim.

I will post something about the internals of Nunchaku some day, it has a cool 5-arguments GADT ;-)

Category: ocaml Tagged: ocaml merlin inotify

Simple Refinements Types for OCaml

Tue 10 March 2015

For more than one year, vulnerabilies in software (especially pervasive C software) have been disclosed at an alarmingly high rate. I love OCaml, which is definitely safer, but still has gaps left open. I believe formal verification, albeit a very powerful tool, is not mature enough for most programmers (too ...

Category: ocaml Tagged: ocaml types refinement

Read More

Batch Operations on Collections

Wed 11 June 2014

Some very common (and useful) operations, including the classic map, filter, and flat_map, traverse their whole argument and return another collection. When several such operations are composed, intermediate collections will be created and become useless immediately after. Languages like Haskell sometimes perform optimizations that merge together the operations so as ...

Category: ocaml Tagged: ocaml flat_map collections performance batch gadt

Read More

Representing Lazy Values

Fri 02 May 2014

A quick survey of Lazy in OCaml

I remember having heard that Jane Street had its own implementation of Lazy values, and that it was faster than the standard one. So I played a bit with several ways of managing lazy values in OCaml.

Definition of Lazy implementations

First we ...

Category: ocaml Tagged: ocaml lazy obj performance

Read More

Go, C++!!

Tue 18 December 2012

I've recently read an interesting article which shows an example of concurrency implemented in 3 differenet languages, namely Go, Erlang and C++. While the Erlang and Go examples seemed clear and concise, the C++ one looks long and hard to understand. The reason behind this complexity is that C ...

Category: concurrency Tagged: c++11 concurrency go

Read More
Page 1 of 2

Next »