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:
- you write an
.ocamlinitfile in one of your project’s sub-directories. - You add only this line.
#use_output "dune ocaml top";; - Now you can execute
utopfrom this sub-directory (justutop, 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.