package core_kernel

  1. Overview
  2. Docs
Industrial strength alternative to OCaml's standard library

Install

Dune Dependency

Authors

Maintainers

Sources

v0.13.1.tar.gz
sha256=2e9dec37cf1b1a05fa3ad24ae8efd1e389b82928d598db097771405da1d6b214
md5=ee4f3b03ce7fa4cb0c27e9b02cc7712d

doc/core_kernel.uopt/Uopt/index.html

Module Uopt

A Uopt.t is an unboxed option. This module is tricky and potentially unsafe. It should mostly not be used, and when it is, one must keep the Uopt.t inside their module, and not expose them (not even if they are given an abstract type).

'a Uopt.t is like 'a option, but doesn't box some values. It must not be used in a nested way, i.e. as 'a Uopt.t Uopt.t. It must also not be used for float Uopt.t array, since the representation of the array would vary depending on whether none or some is used to create the array. It should also not be used in a record that contains only floats and float Uopt.ts, because the compiler would treat that as a float-only record and would unbox the record fields.

The type is exposed as private 'a so the compiler can infer that an 'a t can't be a float in the right context, thus avoiding runtime checks in _ Uopt.t arrays. Using :> is of course unsafe. Because Uopt.none cannot be garbage collected, there is no problem if the compiler decides to skip write barriers (when 'a is an immediate).

type 'a t = private 'a
val sexp_of_t : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a t -> Ppx_sexp_conv_lib.Sexp.t
include Core_kernel.Invariant.S1 with type 'a t := 'a t
val invariant : ('a -> unit) -> 'a t -> unit
val none : _ t
val some : 'a -> 'a t
val is_none : _ t -> bool
val is_some : _ t -> bool
val value_exn : 'a t -> 'a
val unsafe_value : 'a t -> 'a

It is safe to call unsafe_value t iff is_some t.

module Optional_syntax : Core_kernel.Optional_syntax.S1 with type 'a t := 'a t and type 'a value := 'a
OCaml

Innovation. Community. Security.