I have recently been doing some coding in ocaml. So far, so good! However, even after a moderate amount of reading, searching, and even asking in the ocaml discord chat channel, it is clear to me that there are various essential knowledge gaps not well communicated in the manual or in realworldocaml. Here are a handful of hot ocaml bootstrapping tips.
Straight up, https://dev.realworldocaml.org/install.html.
utopREPLs do not resolve modules in the same way your compiler will.
open SomeModuleonly to expose functionality
opam install <some module>, your editor may not pick it up until you've declared it properly in your dune file. 🤯. You may have thought your developer tooling (merlin, ocaml-lsp, & friends) just couldn't locate your package of interest. Fear not, it can, but everything demands that your compiler tooling be aligned as well.
There are various compilers.
dune in 2020. Who knows how this post will age, but start with
dune. Don't bother consider looking at the others.
Read the dune docs.
;dune ;...snip (test (name test) (libraries ounit2 yourmodule) (modules test))
Ensure that you add your testing library/runner and the associated library you want to test. Obnoxiously, because you may have a heirarchy as such:
$ ls -l dune yourmodule.ml test.ml
you must tell
*.ml files should be built by a specfic built
For example, for a layout like:
$ ls -l dune Replacements.ml Redacto.ml test.ml
my dune file looks simliar to:
(library ... (modules replacements)) (executable ... (modules redacto)) (test ... (modules test))
.ml file has one place to be built in dune's eyes.
You read Real World Ocaml, OR, you use existing knowledge of
Promises and use
the lwt library, which >1/2 of the OCaml
ecosystem seems to be aligned around.
No. There's no focused content in video form, at least on YouTube, distilled down in a focused way. Maybe I'll be the guy to make that video ;).
It took searching and finding
Regular Expressions vs Parser Combinators in OCaml
to finally come to a conclusion.
re2 is generally seen as a good pick, but
there is ~nil documentation on how to use it. The
PCRE docs are good. The interfaces
between re2 and pcre are similar, so if you learn one you kind of learn both.
Start with PCRE if you want for ease of learning.
There is a standard library, it is only ok.
core seem to be the go to std libary replacements. And
they literally do replace--override--aspects of the default standard library,
versus an module that has no effect on your build. Don't expect to be able to
have written some ocaml using the standard library, then bring in one of these
and have things just continue to work--some minor refactors may be required.
Install them from
opam, per usual.
As far as I know--you don't.
printf? I've seen some hints that there may be
tooling for emacs users? I've looked at the VSCode extensions, and there are
some promising work out there, but they aren't compatible with
the time of writing.
Isn't it great?