package octez-libs
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65
doc/octez-libs.stdlib/Tezos_stdlib/Compare/index.html
Module Tezos_stdlib.Compare
Source
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
S
is a signature for a fully-fledge comparison module. It includes all the functions and operators derived from a compare
function.
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
.
Int
is a comparison module. Out of performance concerns, the signature actually contains compiler builtins (external
) rather than val
.
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
.
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
..
Building blocks
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)