package core_kernel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Interfaces for use with match%optional. Idiomatic usage is to have a module M like:

module M : sig
  type t

  module Optional_syntax : Optional_syntax.S
    with type t := t
    with type value := ...
end = struct
  ...

  module Optional_syntax = struct
    module Optional_syntax = struct
      let is_none = is_node
      let unchecked_value = unchecked_value
    end
  end
end

Then, uses look like:

let open M.Optional_syntax in
match%optional m with
| None   -> ?
| Some v -> ?

The reason for the double module Optional_syntax is so that open M.Optional_syntax puts in scope only module Optional_syntax; match%optional then expands to references to Optional_syntax.is_none and Optional_syntax.unchecked_value.

For more details on the syntax extension, see ppx/ppx_optional/README.md.

module type S = Optional_syntax.S
module type S1 = Optional_syntax.S1
module type S2 = Optional_syntax.S2
OCaml

Innovation. Community. Security.