Module Order.Ordering

Module for the Ordering type.

Definition

type t = [
| `Less
| `Equal
| `Greater
]

Defines the relative order of two values.

Basics

val invert : t -> t

Inverts a given ordering.

Pretty-printing

val inspect : Format.formatter -> t -> unit

Pretty-printer for values of type t in debugging context.

val display : Format.formatter -> t -> unit

Pretty-printer for values of type t suitable for user-facing output. The constructors Less, Equal and Greater are rendered as mathematical symbols <, = and > respectively.

Equality and Comparison

val equal : t -> t -> bool

Checks if two ordering values are equal. This makes t an instance of Equal0.

val compare : t -> t -> t

Relative ordering of two orderings. This makes t an instance of Ordered0.

Conversions

val to_int : t -> int

Represents an ordering as an integers.

The following mapping is used:

  • Less is -1
  • Equal is 0
  • Greater is 1
val of_int : int -> t

Converts an integer to an ordering.

of_int i is translated as:

  • Less if i < 0
  • Equal if i = 0
  • Greater if i > 0