{"id":21531941,"url":"https://github.com/matrixai/ocaml-demo","last_synced_at":"2026-05-21T10:01:41.442Z","repository":{"id":151338800,"uuid":"160809326","full_name":"MatrixAI/OCaml-Demo","owner":"MatrixAI","description":"OCaml Demo Project","archived":false,"fork":false,"pushed_at":"2018-12-09T08:52:00.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-17T19:31:16.458Z","etag":null,"topics":["ocaml","ocaml-library","ocaml-program"],"latest_commit_sha":null,"homepage":"https://matrix.ai","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatrixAI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-07T10:30:08.000Z","updated_at":"2022-01-09T15:27:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"b8b11ee1-7ba5-4999-87b4-e0bc6a7e20b2","html_url":"https://github.com/MatrixAI/OCaml-Demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MatrixAI/OCaml-Demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2FOCaml-Demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2FOCaml-Demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2FOCaml-Demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2FOCaml-Demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatrixAI","download_url":"https://codeload.github.com/MatrixAI/OCaml-Demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixAI%2FOCaml-Demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33297107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T02:57:32.698Z","status":"ssl_error","status_checked_at":"2026-05-21T02:57:31.990Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ocaml","ocaml-library","ocaml-program"],"created_at":"2024-11-24T02:18:13.053Z","updated_at":"2026-05-21T10:01:41.424Z","avatar_url":"https://github.com/MatrixAI.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OCaml Demo\n\nThis is an example OCaml project using Nix to setup a development environment.\n\nThis uses Dune as its builder and the OCaml Package Manager. Dune replaces `ocamlbuild` and is a more sophisticated builder. The OCaml Package Manager is not used for bringing in dependencies, only as a way to create the `*.opam` file and interaction with the Opam service.\n\nThe Nix derivation in `default.nix` uses the `ocamlPackages.buildDunePackage` function. This function is designed for building OCaml libraries. If you are building an application using OCaml, then you need to use `stdenv.mkDerivation` instead. However if you do so, you need to instead use `name` instead of `pname` and use `buildInputs = with ocamlPackages; [ ocaml dune findlib ]` to bring in the OCaml compilation pipeline. You also need to replicate the `buildPhase`, `checkPhase` and `installPhase` that is in the `buildDunePackage` function. See https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/ocaml/dune.nix for more information.\n\n## Installation\n\nIf on Nix, you can install just by using:\n\n```sh\nnix-env -f ./default.nix -i\n```\n\nIf you are not, then use `make`:\n\n```sh\nmake\nmake install\n```\n\n## Developing\n\nRun `nix-shell`, and once you're inside, you can use:\n\n```sh\nmake\nmake clean\nutop\ndune build -p ocaml-demo\ndune runtest -p ocaml-demo\n```\n\nThe `Makefile` is conventionally used to abstract the OCaml builder commands, in this case that's `dune`. Use `make; make install PREFIX=/tmp;` to build the OCaml project into the `./_build` directory and subsequently install it in the relevant prefix.\n\nAdding a new package can be done by inserting them into the `buildInputs` attribute of `default.nix`. You'll notice that `opam` and `utop` are in the `shell.nix` because they are only needed during development.\n\nInside `./bin` and `./src`, there are `dune` files. These files provide the metadata for how to compile the OCaml code. Code inside `./bin` will be compiled into executables. While `./src` will become libraries.\n\nUse `utop` as an OCaml REPL:\n\n```sh\ndune utop src\n```\n\nThis will load all the OCaml modules inside `src` into the `utop` REPL.\n\nOnce you are finished developing, you can build the package using:\n\n```sh\nnix-build\n```\n\nUsing `dune` inside the `nix-shell` allows more granular control over compilation outputs.\n\nThese are all possible:\n\n```sh\ndune build bin/hello.exe\ndune build bin/hello.exe.o\ndune build bin/hello.bc\ndune build bin/hello.bc.o\ndune build bin/hello.bc.so\ndune build bin/hello.so\ndune build bin/hello.bc.js\n```\n\nIt depends on the `modes` property inside the `./bin/dune` file.\n\n```\n(modes\n  (native exe)\n  (byte exe)\n  (native shared_object)\n  (byte shared_object)\n  (native object)\n  (byte object))\n```\n\nOCaml has a byte code compiler and native code compiler. In most cases you will prefer to use the native code compiler.\n\nAll executables in dune are produced as `.exe` extension regardless of which platform you're on. However afterwards the executables can be renamed to the appropriate extension on the target platform.\n\nYou can then run also execute specific executables:\n\n```sh\ndune exec bin/hello.exe\n```\n\nTo run tests, just use:\n\n```sh\ndune runtests -p ocaml-demo\n```\n\nTo publish an Opam package:\n\n```sh\ngit tag 0.0.1\ngit push 0.0.1\nopam publish\n```\n\nNote that the way Nix constructs the necessary compilation environment is through a setup hook in the `ocamlPackages.findlib` dependency. This setup hook creates the `OCAMLPATH` envrionment variable which points to every OCaml dependency.\n\n## Other Documentation\n\n* https://dune.readthedocs.io/en/latest\n* https://medium.com/@bobbypriambodo/starting-an-ocaml-app-project-using-dune-d4f74e291de8\n\n---\n\nOCaml files are compiled into \"modules\". The files are always lowercased, but the module names are StudylyCaps.\n\nThe modules that are in a directory with a `dune` file are given a \"library name\". This name itself becomes another module. Other OCaml programs refer to the library by its public name, and can use it like a module using `open Library`. In that case any modules inside that library is also capable of being used.\n\nHowever if the \"library name\" conflicts with a module name, that module becomes the library. Think of that module as the index of that library. It's sort of like the `__init__.py` file in Python modules.\n\nRight now inside the `./src` directory, we have `demo.ml`. This acts as the index module of the `demo` library specified in `./src/dune`. Had there been no `demo.ml`, then the `demo` library is just a module containing the `Math` module derived from the `./src/math.ml`.\n\nThe directory name does not matter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixai%2Focaml-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatrixai%2Focaml-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixai%2Focaml-demo/lists"}