package ocaml-version

  1. Overview
  2. Docs

Manipulate, parse and generate OCaml version strings.

These are of the form major.minor.patch+extra, where the patch and extra fields are optional.

Core types and parsers and serializers

type t

Type of an OCaml version string

val v : ?patch:int -> ?extra:string -> int -> int -> t

v ?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.

val to_string : ?sep:char -> t -> string

to_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

of_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 -> t

of_string_exn t behaves as of_string but raises Invalid_argument if the string cannot be parsed.

val compare : t -> t -> int

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 : Format.formatter -> t -> unit

pp fmt t will output a human-readable version string of t to the fmt formatter.

Architecture Support

These definitions cover the CPU architectures that OCaml runs and is supported on.

type arch = [
  1. | `X86_64
  2. | `Aarch64
]

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 arches : arch list

arches is an enumeration of all of the possible arch values.

val string_of_arch : arch -> string

string_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

arch_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 -> arch

arch_of_string_exn t is the same as arch_of_string, except that it raises Invalid_argument in case of error.

Accessors

val major : t -> int

major 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 -> int

minor 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 option

patch 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 option

extra t will return the additional information string of an OCaml release. For example, of_string "4.03.0+flambda" |> extra will return Some "flambda".

val with_variant : t -> string option -> t

with_variant t extra will return a fresh value with the extra version information in the OCaml string to extra, and remove it if None is supplied.

Constants

val sys_version : t

sys_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 ... end

Values representing official releases of OCaml.

Feature Selection

module Since : sig ... end

Determine which release a feature or architecture first appeared in.

module Has : sig ... end

Test whether a release has a given feature.

module Opam : sig ... end

Opam compiler switches. These are available from the public opam-repository.

OCaml

Innovation. Community. Security.