I’m quite new to OCaml and I’m rooting for https://preview.dune.build/
Knowing very little about anything really I cannot figure out how to install and actual dependency.
I think I’m looking for the npm install foo equivalent in the new dune world.
I created a project using dune init project my_name.
And now I’d like to play around with ppx_deriving.
Their GitHub says opam install ppx_deriving, so I thought dune install ppx_deriving would do the trick but nothing happens:
Error: Unknown package ppx_deriving!
I also updated my bin/main.ml to
type coord = { x : int; y : int }
let () = print_endline "Hello, World!"
This now does not compile:
dune build:
File "bin/main.ml", line 1, characters 0-33:
1 | type coord = { x : int; y : int }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error (warning 34 [unused-type-declaration]): unused type coord.
File "bin/main.ml", line 1, characters 15-23:
1 | type coord = { x : int; y : int }
^^^^^^^^
Error (warning 69 [unused-field]): unused record field x.
File "bin/main.ml", line 1, characters 24-31:
1 | type coord = { x : int; y : int }
^^^^^^^
Error (warning 69 [unused-field]): unused record field y.
This is all rather strict, can I treat this warning as a warning?
Lastly, what do I tell the ocaml vscode extension:
The current Merlin configuration has been generated by another, incompatible, version of Dune. Please rebuild the project. (Using the same version of Dune as the one running the 'ocaml-merlin' server.)ocamllsp
There is no explicit install step. You’d want to add ppx_deriving to your dune-project file, then call dune pkg lock (which dune tells you to do IIRC), and the next build will download/build any new dependencies. Doc: Managing Dependencies - Dune documentation.
dune install is not comparable to opam install, I guess its functionality and name is taken from the make install convention.
You can add [@@@ocaml.warnerror "-34-69"] at the top of your file. The problem with warnings-as-not-errors is that warnings will only be given when the file is compiled. So if you run dune build && dune build, the second build will never report any warning.
The tutorial should explain how to setup dev tools, but since it doesn’t, I think this post is the only written explanation.
I would suggest you go through the OCaml Package Management with Dune tutorial, which we wrote to explain how to use it. The developer preview website has been updated with links to both the tutorial and the in-depth explanation.
The fact that opam install <package> has no direct Dune equivalent is a deliberate decision, as we want all package configuration derive from configuration files, thus to add dependencies you need to update your configuration. That doesn’t mean that there won’t be a command to add dependencies, but even then it will just update the config files, thus the dune-project etc. will always be the source of truth for your package dependencies.
dune install predates package management by a few years and is used for something different. Generally I recommend not using it, since what it does is mostly done better using other ways. It indeed is more similar to make install, which for OCaml packages I would also recommend against.
dune install predates package management by a few years and is used for something different. Generally I recommend not using it, since what it does is mostly done better using other ways.
The issue with dune install is that it installs into your switch by copying files there, thus OPAM doesn’t know about it and it can’t manage packages installed that way (and if you install the same package via OPAM or reinstall/update packages this can lead to some unpleasantries).
A better solution do so is to use pinning in OPAM, thus OPAM knows what it installed, what version it is and how to uninstall it and will also rebuild it if needed. Alternatively, if you don’t really care about things being installed in your switch and are using Dune, you can copy/symlink the project into your source directory and then Dune will build and use the “vendored” copy, without having to look into the switch.