OCaml: Difference between revisions
m put languages on the bottom of the page |
Updated OCaml language by providing additional references to Nixpkgs manual. |
||
| Line 1: | Line 1: | ||
[[File:OCaml Logo.svg|alt=The OCaml logo: an orange background with a white foreground of a camel.|thumb|OCaml logo]] | |||
According to the official [ocaml.org Ocaml website]:<blockquote> | |||
[Ocaml is]... an industrial-strength functional programming language with an emphasis on expressiveness and safety </blockquote> | |||
== Developping in OCaml with Nix == | |||
Most packages related to OCaml, in particular the OCaml compiler and many libraries, belong to the '''ocamlPackages''' attribute set of nixpkgs. Tools for OCaml development are, in particular, available: | |||
* the [https://dune.build/ dune] builder; | |||
* the [https://github.com/ocaml/ocaml-lsp OCaml language server]; | |||
* the [https://github.com/ocaml-ppx/ocamlformat ocamlformat formatter]. | |||
=== Build tooling === | |||
Modern development practices in OCaml tend to use '''dune''', a builder dedicated for OCaml projects. Nixpkgs provide a dedicated builder: [https://nixos.org/manual/nixpkgs/stable/#sec-language-ocaml-packaging buildDuneProject]. | |||
'''dune''' can generate a '''.opam''' file, which can be ingested by tools like [https://github.com/tweag/opam-nix opam-nix] to automatically generate a derivation. | |||
Manual package building is also possible using the following approaches: | |||
==== Findlib, ocamlfind ==== | |||
OCaml libraries are usually located using [http://projects.camlcity.org/projects/findlib.html findlib] and the associated '''ocamlfind''' tool. These tools are found under the '''ocamlPackages.findlib''' attribute and rely on the '''OCAMLPATH''' environment variable. | OCaml libraries are usually located using [http://projects.camlcity.org/projects/findlib.html findlib] and the associated '''ocamlfind''' tool. These tools are found under the '''ocamlPackages.findlib''' attribute and rely on the '''OCAMLPATH''' environment variable. | ||
| Line 11: | Line 31: | ||
This hook also sets the '''CAML_LD_LIBRARY_PATH''' environment variable that is used for locating the dynamically loaded shared libraries (aka stublibs). | This hook also sets the '''CAML_LD_LIBRARY_PATH''' environment variable that is used for locating the dynamically loaded shared libraries (aka stublibs). | ||
== Scripting with OCaml == | === Scripting with OCaml === | ||
OCaml can be used in nix-shell scripts as follows: | OCaml can be used in nix-shell scripts as follows: | ||
<syntaxHighlight lang=ocaml> | <syntaxHighlight lang=ocaml> | ||
| Line 22: | Line 42: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== Using Emacs == | === Using Emacs === | ||
[https://github.com/ocaml/tuareg Tuareg] is an Emacs OCaml mode. It can be installed with | [https://github.com/ocaml/tuareg Tuareg] is an Emacs OCaml mode. It can be installed with | ||
<code>nix-env -iA nixpkgs.emacsPackagesNg.tuareg</code>. | <code>nix-env -iA nixpkgs.emacsPackagesNg.tuareg</code>. | ||
| Line 61: | Line 80: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== Specific version of the OCaml compiler == | === Specific version of the OCaml compiler === | ||
Various versions of the '''ocamlPackage''' attribute set are available, corresponding to various versions of OCaml. For instance, the attribute set '''ocaml-ng.ocamlPackages_4_04''' contains the OCaml compiler at version 4.04 and OCaml libraries compiled with that particular compiler. | Various versions of the '''ocamlPackage''' attribute set are available, corresponding to various versions of OCaml. For instance, the attribute set '''ocaml-ng.ocamlPackages_4_04''' contains the OCaml compiler at version 4.04 and OCaml libraries compiled with that particular compiler. | ||
=== Custom version === | ==== Custom version ==== | ||
So as to get the set of OCaml libraries built with/for a custom version of the OCaml compiler, e.g., to enable '''flambda''' support, you may use the '''ocamlPackages.overrideScope''' function: | So as to get the set of OCaml libraries built with/for a custom version of the OCaml compiler, e.g., to enable '''flambda''' support, you may use the '''ocamlPackages.overrideScope''' function: | ||