package base

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type t =
  1. | Atom of string
  2. | List of t list
include sig ... end
val hash_fold_t : Hash.state -> t -> Hash.state
val hash : t -> Hash.hash_value
val t_of_sexp : t -> t
val sexp_of_t : t -> t
exception Of_sexp_error of exn * t

Of_sexp_error (exn, sexp) the exception raised when an S-expression could not be successfully converted to an OCaml-value.

Helpers

val message : string -> (string * t) list -> t

Helper to build nice s-expressions for error messages. It imitates the behavior of [%message ...] from the ppx_sexp_message rewriter.

message name key_values produces a s-expression list starting with atom name and followed by list of size 2 of the form (key value). When the key is the empty string, value is used directly instead as for [%message].

For instance the following code:

Sexp.message "error"
  [ "x", sexp_of_int 42
  ; "" , sexp_of_exn Exit
  ]

produces the s-expression:

(error (x 42) Exit)

Defaults

val default_indent : int Caml.ref

default_indent reference to default indentation level for human-readable conversions.

Initialisation value: 2.

Pretty printing of S-expressions

val pp_hum : Caml.Format.formatter -> t -> unit

pp_hum ppf sexp outputs S-expression sexp to formatter ppf in human readable form.

val pp_hum_indent : int -> Caml.Format.formatter -> t -> unit

pp_hum_indent n ppf sexp outputs S-expression sexp to formatter ppf in human readable form and indentation level n.

val pp_mach : Caml.Format.formatter -> t -> unit

pp_mach ppf sexp outputs S-expression sexp to formatter ppf in machine readable (i.e. most compact) form.

val pp : Caml.Format.formatter -> t -> unit

Same as pp_mach.

Conversion to strings

val to_string_hum : ?indent:int -> t -> string

to_string_hum ?indent sexp converts S-expression sexp to a string in human readable form with indentation level indent.

  • parameter indent

    default = !default_indent

val to_string_mach : t -> string

to_string_mach sexp converts S-expression sexp to a string in machine readable (i.e. most compact) form.

val to_string : t -> string

Same as to_string_mach.

Styles

val of_float_style : [ `Underscores | `No_underscores ] Caml.ref
val of_int_style : [ `Underscores | `No_underscores ] Caml.ref
module Private : sig ... end
include Comparable.S with type t := t
include Comparable_intf.Polymorphic_compare with type t := t
include Polymorphic_compare_intf.Infix with type t := t
val (>=) : t -> t -> bool
val (<=) : t -> t -> bool
val (=) : t -> t -> bool
val (>) : t -> t -> bool
val (<) : t -> t -> bool
val (<>) : t -> t -> bool
val equal : t -> t -> bool
val compare : t -> t -> int

-1 means "less than", 0 means "equal", 1 means "greater than", and other values should not be returned

val min : t -> t -> t
val max : t -> t -> t
val ascending : t -> t -> int

ascending is identical to compare. descending x y = ascending y x. These are intended to be mnemonic when used like List.sort ~cmp:ascending and List.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.

val descending : t -> t -> int
val between : t -> low:t -> high:t -> bool
val clamp_exn : t -> min:t -> max:t -> t

clamp_exn t ~min ~max returns t', the closest value to t such that between t' ~low:min ~high:max is true.

Raises if not (min <= max).

val clamp : t -> min:t -> max:t -> t Or_error.t
include Comparator.S with type t := t
type comparator_witness
include Comparable_intf.Validate with type t := t
val validate_lbound : min:t Maybe_bound.t -> t Validate.check
val validate_ubound : max:t Maybe_bound.t -> t Validate.check
val validate_bound : min:t Maybe_bound.t -> max:t Maybe_bound.t -> t Validate.check
OCaml

Innovation. Community. Security.