package octez-libs

  1. Overview
  2. Docs
A package that contains multiple base libraries used by the Octez suite

Install

Dune Dependency

Authors

Maintainers

Sources

octez-19.0.tar.gz
sha256=c6df840ebbf115e454db949028c595bec558a59a66cade73b52a6d099d6fa4d4
sha512=d8aee903b9fe130d73176bc8ec38b78c9ff65317da3cb4f3415f09af0c625b4384e7498201fdb61aa39086a7d5d409d0ab3423f9bc3ab989a680cf444a79bc13

doc/octez-libs.stdlib/Tezos_stdlib/Compare/index.html

Module Tezos_stdlib.CompareSource

Compare

Monomorphic comparison for common ground types and common type constructors.

Compare provides a module signature for the standard comparison functions and operators as well as modules of that signature for the common OCaml ground types (int, bool, etc.) and type constructors (list, option, etc.).

Compare also provides some additional helpers for comparison-related tasks.

Signatures and a functor

Sourcemodule type COMPARABLE = sig ... end

COMPARABLE is a signature for basic comparison. It is used only for instantiating full comparison modules of signature S via the functor Make.

Sourcemodule type S = sig ... end

S is a signature for a fully-fledge comparison module. It includes all the functions and operators derived from a compare function.

Sourcemodule Make (P : COMPARABLE) : S with type t := P.t

Base types

The specialised comparison and all the specialised functions and operators on the base types are compatible with the polymorphic comparison and all the polymorphic functions and operators from the Stdlib.

Sourcemodule Char : S with type t = char
Sourcemodule Bool : S with type t = bool
Sourcemodule Int : sig ... end

Int is a comparison module. Out of performance concerns, the signature actually contains compiler builtins (external) rather than val.

Sourcemodule Int32 : S with type t = int32
Sourcemodule Uint32 : S with type t = int32
Sourcemodule Int64 : S with type t = int64
Sourcemodule Uint64 : S with type t = int64
Sourcemodule Float : S with type t = float
Sourcemodule String : S with type t = string
Sourcemodule Bytes : S with type t = bytes
Sourcemodule Z : S with type t = Z.t

Z is a comparison module for Zarith numbers.

module Q : S with type t = Q.t

Q is a comparison module for Zarith-based rational numbers.

Type constructors

Provided the functor argument(s) are compatible with the polymorphic comparison of the Stdlib, then the specialised comparison and all the specialised functions and operators on the derived types are compatible with the polymorphic comparison and all the polymorphic functions and operators from the Stdlib.

Sourcemodule List (P : COMPARABLE) : S with type t = P.t list
Sourcemodule Option (P : COMPARABLE) : S with type t = P.t option
Sourcemodule Result (Ok : COMPARABLE) (Error : COMPARABLE) : S with type t = (Ok.t, Error.t) result

List lengths

Helpers for more readable Stdlib.List.compare_lengths and Stdlib.List.compare_length_with.

These modules are intended to be used as Module.(expression), most often within an if condition. E.g.,

if Compare.List_length_with.(chunks > max_number_of_chunks) then
   raise Maximum_size_exceeded
else
   ..
Sourcemodule List_length_with : sig ... end
Sourcemodule List_lengths : sig ... end

Building blocks

Sourceval or_else : int -> (unit -> int) -> int

or_else c f is c if c <> 0 or f () otherwise.

The intended use is

let compare (foo_a, bar_a) (foo_b, bar_b) =
  or_else (Foo.compare foo_a foo_b) (fun () -> Bar.compare bar_a bar_b)
OCaml

Innovation. Community. Security.