ocamlocaml-core

How do you determine the version of OCaml or Jane Street Core library at runtime


I am migrating to a recent version of OCaml (and Jane Street's Core modules), but would like my code to continue to compile with older versions. To do so, I would like to create a module with portable functions that map to either the old or new interfaces depending on the version. Querying both the version of OCaml and the version of Jane Street Core would work.

How can we look up the version of the compiler or of Jane Street Core at runtime? I know that I could pass the output of ocamlopt --version via my build system, but ideally I should not have to invoke my programs in a special way.


Solution

  • You can retrieve the OCaml version number with Sys.ocaml_version.

    utop # Sys.ocaml_version;;
    - : string = "4.13.1"
    

    I'm afraid after browsing the Jane Street Base and Core API docs, I don't see a way to query the version number at runtime.