Dune build -w; dune utop; edit - recompile - reload

I wanted to do this a few days ago, you may find a few useful ideas here: Can I "reset" my REPL? - #3 by benjamin-thomas

Since then, I found another neat option which is good for little examples.

It’s document here: Toplevel Integration — Dune documentation

And not very obvious from an outsider’s perspective. In short:

  1. you write an .ocamlinit file in one of your project’s sub-directories.
  2. You add only this line. #use_output "dune ocaml top";;
  3. Now you can execute utop from this sub-directory (just utop, no dune prefix)

On entering utop, your module will be compiled “automagically”, no need for dune build.

Just ctrl+d out of utop then re-enter and you’ll have you’re latest module available, newly compiled (the recompilation is very fast).

I haven’t played with this technique extensively yet but it feels great for little examples and code exploration.

1 Like