Frama-C:
Plug-ins:
Libraries:

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

  • since 31.0-Gallium
include Monad.S_with_product with type 'a t = 'a option
val return : 'a -> 'a option
val flatten : 'a option option -> 'a option
val product : 'a option -> 'b option -> ('a * 'b) option
module Bool : sig ... end
module Option : sig ... end
module List : sig ... end
module Operators : sig ... end
include module type of Stdlib.Option
type !'a t = 'a option =
  1. | None
  2. | Some of 'a
val none : 'a option
val some : 'a -> 'a option
val value : 'a option -> default:'a -> 'a
val join : 'a option option -> 'a option
val map : ('a -> 'b) -> 'a option -> 'b option
val fold : none:'a -> some:('b -> 'a) -> 'b option -> 'a
val iter : ('a -> unit) -> 'a option -> unit
val is_none : 'a option -> bool
val is_some : 'a option -> bool
val equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> bool
val compare : ('a -> 'a -> int) -> 'a option -> 'a option -> int
val to_result : none:'e -> 'a option -> ('a, 'e) Stdlib.result
val to_list : 'a option -> 'a list
val to_seq : 'a option -> 'a Stdlib.Seq.t
val bind : ('a -> 'b t) -> 'a t -> 'b t

Reverse 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 -> 'a

Redefines Stdlib.Option.get with a exn parameter.

  • raises Exn

    if the value is None and exn is specified.

  • raises Invalid_argument

    if the value is None and exn is not specified.

  • returns

    v if the value is Some v.

  • since Frama-C+dev
val hash : ('a -> int) -> 'a option -> int

Compute a hash for the option given a hash for the element.

  • since Frama-C+dev
val merge : ('a -> 'a -> 'a) -> 'a option -> 'a option -> 'a option

Merges two options such that

  • merge None None = None
  • merge (Some a) None = Some a
  • merge None (Some b) = Some b
  • merge (Some a) (Some b) = Some (f a b) See also product and map2 for other ways to combine options.
  • since Frama-C+dev
val map2 : ('a -> 'b -> 'c) -> 'a option -> 'b option -> 'c option

Maps two options such that

  • map2 None None = None
  • map2 (Some a) None = None
  • map2 None (Some b) = None
  • map2 (Some a) (Some b) = Some (f a b) See also product and merge for other ways to combine options.
  • since Frama-C+dev
val map_no_copy : ('a -> 'a) -> 'a option -> 'a option

Same as Stdlib.Option.map but avoid creating a copy of the option if the mapped function returns its argument (tested through physical equality).

  • since Frama-C+dev
val filter : ('a -> bool) -> 'a option -> 'a option

filter 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.

  • since Frama-C+dev