My focus is on using Ocaml tools for coding programs.
I’m far away from my first “Hello World!” in OCaml. And I think I’m also quite far away from being able to create an OCaml program for Real World.
Learning OCaml language (stdlib), setting up a working OCaml editor/IDE, evaluating which stdlib replacement was a quite long and painful story (and is still, especially regarding stdlib replacement which highly conditions the way of writing an OCaml program).
I’ve installed Opam, Findlinb and Dune.
Now, I’ve read most of their documentation and experimented them with the CLI on sample programs/projects. I’ve also read various articles (too often not up to date or with errors making learning difficult).
Where is specified the way an ocaml project must be structured?
I mean how to structure the source code tree within a bin/, a src/, a lib/ directories, with the configuration files (mainly META Findlib files, opam or .opam Opam file, and the many dune files)
Are they some templates generated by the tools?
How far is it automated and which information should be added manually?
This is far from being obvious, especially because of the fast moving transformation we encounter.
For example, if I want to program in OCaml, I need a compiler and all individual compiled modules whether they come from a library, a package, or some of my modules possibly gathered in a library.I must use tools for that, mainly Findlib and Opam. But this will not prevent me from trouble.
To avoid “known problems” ( discussed regarding how Opam, Dune, and Findlib are naming and using sets of “resources” @Leonidas recommends to create a local switch in the project and to to use an opam file that will trigger the installation of packages:
As a stopgap solution I recommend using clean switches per project and only install packages via dependencies declared in the
opamfile and avoiding to call
opam install …directly
This is possible with Opam 2 (
$ opam switch create foo <package-or-version> then
$ opam pin edit foo to edit it).
Thanks for that. But Hu!! Imagine the pain for a complete beginner stuck in the middle with a recommended OCaml setup…
We are asked in the documentation to write .merlin files so Merlin can do its job with our libraries. But in fact, Dune generates .merlin files. Great. Now I know!
A build system for OCaml programs?
Dune seems to be a promising one.
But do people write manually all their dune files distributed in their source trees? This seems very error prone.
Is there a Dune function such as the Opam
$ opam pin ... for editing all the dune files?
Is it possible to define in one place all the dependencies for a program (or project) with real-time checking (especially regarding modules/libraries/packages compatibilities)? Once it’s done, we can focus on writing .ml and .mli files and just test it.
And we also have/need the files README.md, LICENSE.md, CHANGES.md, etc.
Is there a template and checking tool for that?
And of course, we may have configuration files for Version control (Git) and CI tools (Travis).
That’s a bunch of files.