Frama-C API - Option
Extension of OCaml's Stdlib.Option module. Be wary that the parameters order of the bind function are reversed compared to the standard library and that get takes an optional exn argument. @see https://frama-c.com/download/frama-c-plugin-development-guide.pdf
include Monad.S_with_product with type 'a t = 'a option
val return : 'a -> 'a optionval flatten : 'a option option -> 'a optionval product : 'a option -> 'b option -> ('a * 'b) optionmodule Bool : sig ... endmodule List : sig ... endinclude module type of Stdlib.Option
type !'a t = 'a option = | None| Some of 'a
val some : 'a -> 'a optionval value : 'a option -> default:'a -> 'aval join : 'a option option -> 'a optionval map : ('a -> 'b) -> 'a option -> 'b optionval fold : none:'a -> some:('b -> 'a) -> 'b option -> 'aval iter : ('a -> unit) -> 'a option -> unitval is_none : 'a option -> boolval is_some : 'a option -> boolval equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> boolval compare : ('a -> 'a -> int) -> 'a option -> 'a option -> intval to_result : none:'e -> 'a option -> ('a, 'e) Stdlib.resultval to_list : 'a option -> 'a listval to_seq : 'a option -> 'a Stdlib.Seq.tval bind : ('a -> 'b t) -> 'a t -> 'b tReverse Stdlib.Option.bind parameters for monad compatibility. bind f o is f v if o is Some v and None if o is None.
val get : ?exn:exn -> 'a option -> 'aRedefines Stdlib.Option.get with a exn parameter.
val hash : ('a -> int) -> 'a option -> intCompute a hash for the option given a hash for the element.
val merge : ('a -> 'a -> 'a) -> 'a option -> 'a option -> 'a optionMerges two options such that
merge None None = Nonemerge (Some a) None = Some amerge None (Some b) = Some bmerge (Some a) (Some b) = Some (f a b) See also product and map2 for other ways to combine options.
val map2 : ('a -> 'b -> 'c) -> 'a option -> 'b option -> 'c optionMaps two options such that
map2 None None = Nonemap2 (Some a) None = Nonemap2 None (Some b) = Nonemap2 (Some a) (Some b) = Some (f a b) See also product and merge for other ways to combine options.
val map_no_copy : ('a -> 'a) -> 'a option -> 'a optionSame as Stdlib.Option.map but avoid creating a copy of the option if the mapped function returns its argument (tested through physical equality).
val filter : ('a -> bool) -> 'a option -> 'a optionfilter f (Some a) applies f to a and returns Some a if f a is true or None if f a is false. filter f None always returns None.