Module type Immediate_option_intf.S_without_immediate_plain
type value
The immediate value carried by the immediate option.
Given the presence of
unchecked_value
, thevalue
type should not have operations that depend on the value's validity for memory safety. In particular,unchecked_value
is not calledunsafe_value
as it would be if it could return a value that later resulted in a segmentation fault. For pointer-like values, useExt
.Nullable, for example.
type t
Represents
value option
without allocating aSome
tag. The interface does not enforce thatt
is immediate because some types, likeInt63.t
, are only immediate on 64-bit platforms. For representations whose type is immediate, useS
below which adds the[@@immediate]
annotation.
val none : t
val some : value -> t
val some_is_representable : value -> Core_kernel__.Import.bool
For some representations of immediate options, the encodings of
none
andsome
overlap. For these representations,some_is_representable value = false
ifvalue
cannot be represented as an option. For example,Int.Option
usesmin_value
to representnone
. For other representations,some_is_representable
always returnstrue
.
val is_none : t -> Core_kernel__.Import.bool
val is_some : t -> Core_kernel__.Import.bool
val value : t -> default:value -> value
value (some x) ~default = x
andvalue none ~default = default
.
val value_exn : t -> value
value_exn (some x) = x
.value_exn none
raises. UnlikeOption.value_exn
, there is no?message
argument, so that calls tovalue_exn
that do not raise also do not have to allocate.
val unchecked_value : t -> value
unchecked_value (some x) = x
.unchecked_value none
returns an unspecified value.unchecked_value t
is intended as an optimization ofvalue_exn t
whenis_some t
is known to be true.
val to_option : t -> value Core_kernel__.Import.option
val of_option : value Core_kernel__.Import.option -> t
module Optional_syntax : Core_kernel.Optional_syntax.S with type t := t with type value := value