val v : ?patch:int -> ?extra:string -> int -> int -> tv ?patch ?extra major minor will construct an OCaml version string with the appropriate parameters. The patch and extra indicators are optional, but it is conventional to include a patch value of 0 for most recent OCaml releases.
Parsers and serializers
val to_string : ?sep:char -> t -> stringto_string ?sep t will convert the version t into a human-readable representation. The sep will default to + which is the normal representation of extra version strings, but can be changed to another character by supplying sep. One such usecase is to generate Docker container tags from OCaml version strings, where only dashes and alphanumeric characters are allowed.
val of_string : string -> (t, [> `Msg of string ]) Result.resultof_string t will parse the version string in t. The return value is compatible with the Result combinators defined in the rresult library.
val of_string_exn : string -> tof_string_exn t behaves as of_string but raises Invalid_argument if the string cannot be parsed.
equal a b is the equality function for two OCaml version strings. Returns true if they are equal, false if they are not.
compare a b is the comparison function for two OCaml version strings. Returns -1 if a<b, 0 if they are equal and 1 if a>b. Comparison is done using integer comparison for the major, minor and patch versions, and lexical comparison for any extra version strings present.
val pp : Stdlib.Format.formatter -> t -> unitpp fmt t will output a human-readable version string of t to the fmt formatter.
Architecture Support
Type of CPU architectures. TODO: This is currently an incomplete list, and lists just those used by the opam test systems. Contributions welcome to complete it.
val string_of_arch : arch -> stringstring_of_arch arch will convert arch into a human-readable CPU architecture string. The result will follow the GOARCH convention used by Golang.
val arch_of_string : string -> (arch, [> `Msg of string ]) Result.resultarch_of_string t will parse the architecture string in t. The return value is compatible with the Result combinators defined in the rresult library. This function is liberal and will attempt to understand variants of the same architecture. For example, both aarch64 and arm64 are parsed into `Aarch64.
val arch_of_string_exn : string -> archarch_of_string_exn t is the same as arch_of_string, except that it raises Invalid_argument in case of error.
val arch_is_32bit : arch -> boolarch_is_32bit t will return true if the architecture has a 32-bit wordsize.
Accessors
val major : t -> intmajor t will return the major version number of an OCaml release. For example, of_string "4.03.0" |> major will return 4.
val minor : t -> intminor t will return the minor version number of an OCaml release. For example, of_string "4.03.0" |> minor will return 3.
val patch : t -> int optionpatch t will return the patch version number of an OCaml release. For example, of_string "4.03.0" |> minor will return Some 0.
val extra : t -> string optionextra t will return the additional information string of an OCaml release. For example, of_string "4.03.0+flambda" |> extra will return Some "flambda".
with_variant t extra will return a fresh value with the extra version information in t to extra, and remove it if None is supplied.
without_variant t is with_variant t None. It removes any extra version information from the version string t.
with_patch t patch will return a fresh value with the patch number in t to patch, and remove it if None is supplied.
without_patch t is as with_patch t None. It removes the least significant number from the version string. This is useful for the Docker OCaml containers, which are all named without a patch number and compiled using the latest patch release (e.g. 4.06 instead of 4.06.1).
with_just_major_and_minor t strips out any patch and extra version information to return the X.Y form of the OCaml release. For example, 4.08.0+trunk+flambda will return the version representing 4.08.
Constants
val sys_version : tsys_version is the version of OCaml that this library is currently compiled with, which will be the same as Sys.ocaml_version.
module Releases : sig ... endValues representing official releases of OCaml.
module Sources : sig ... endValues relating to the source code and version control of OCaml
Feature Selection
module Since : sig ... endDetermine which release a feature or architecture first appeared in.
module Has : sig ... endTest whether a release has a given feature.
module Configure_options : sig ... endConfiguration parameters that affect the behaviour of OCaml at compiler-build-time.
val compiler_variants : arch -> t -> Configure_options.o list listcompiler_variants v returns a list of configuration options that are available and useful for version v of the compiler.
module Opam : sig ... endOpam compiler switches. These are available from the public opam-repository.