How does one create a proper OCaml project?

How do I use files like Makefiles, dune, _tags, .ocamlinit, and other to make a proper OCaml project?
What do I have to do to be able to use online libraries into my projects?
And finally, what manners should I adopt while coding ? (ie modular programming?)

I want to be able to easily run tests, compile, and setup a new project.
Maybe already existing tools could help.

I’m on Ubuntu and I’m coding with Emacs with Tuareg installed for the moment.

1 Like

I don’t know the canonical way, but I manually create/copy files and directories like at mro/Tagger: ♊️ Mirror of https://code.mro.name/mro/Tagger | 🐫 Add, delete and list tags of files stored in filenames. - Tagger - Codeberg.org – namely the mentioned dune, Makefile etc.

It’s so easy done, I didn’t research automation.

This may help:

For project template generators: either use dune init ... as in the tutorial above or GitHub - tmattio/spin: OCaml project generator. (this can be installed by running opam install spin)

1 Like

I keep hello as a generic minimal OCaml project as a starting point.

2 Likes

Another option is drom, which is similar to spin, but also wraps opam and dune commands, as well as publishing to github.

OCaml Best Practices => bootstrap

4 Likes

I personally use Oskel
which is rather customizable.

A complete project comprises of several (opinionated) files like Makefile, CI, tests and so on. That is why dune init is not a complete solution. A skeleton generator is convenient but it is difficult to maintain by itself. Hence why I am not too convinced by them and think a collection of generic GitHub repos is a good idea (or one repo with several branches for various use cases). There could be a command that clones and instantiates them.

There are a few options, all of which are “proper”: running test executables with dune, dune cram tests, alcotest, dune inline tests with ppx_inline_tests, dune inline tests with qtest, qcheck, coverage reports with bisect_ppx, etc.

If you want us to chime in on the pros and cons of our favourites, I would suggest starting a separate thread for testing.

2 Likes