ocaml-core / base / core / lib / default.mli

(* [Default] is used to create new types for specifying default values for optional
   arguments, and having the type checker enforce the default.

   For example, to represent optional boolean arguments with default values [true] and
   [false], in bool.mli we have:

     module True_  : Default.S with type real = t
     module False_ : Default.S with type real = t

   In we create the modules using [Default.create], specifying the default value
   as the argument:

     module  True_ = (val Default.create true  : Default.S with type real = t)
     module False_ = (val Default.create false : Default.S with type real = t)

   Here is how to specify and define a function that uses optional arguments with
   enforced defaults:

     let f
       :  ?x:Bool. True_.default
       -> ?y:Bool.False_.default
       -> unit
       -> bool * bool
       = fun ?(x = Bool.True_.default) ?(y = Bool.False_.default) () ->
       let x = (x :> bool) in
       let y = (y :> bool) in
       x, y

   And here is how to call [f], using the override [!!] prefix operator, which is defined
   in Core to be [Default.override].

     let () =
       assert ((true , false) = f ());
       assert ((false, false) = f ~x:!!false ());
       assert ((false, true ) = f ~x:!!false ~y:!!true ());

   For more discussion, see:

type ('real, 'phantom) t = private 'real

val override : 'real -> ('real, _) t

module type S = sig
  type phantom
  type real
  type default = (real, phantom) t
  val default : default

val create : 'a -> (module S with type real = 'a)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.