package core_kernel

  1. Overview
  2. Docs
Industrial strength alternative to OCaml's standard library

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.0.tar.gz
sha256=fd2b8c6715794df7a810a62b226f53720f211cd344b4afc9fab0498796d6b466

doc/src/core_kernel.enum/enum_intf.ml.html

Source file enum_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
open! Base

module type Sexp_of = sig
  type t [@@deriving sexp_of]
end

module type Single = sig
  (** These functions take single values of ['a] instead of enumerating all of them. *)

  type 'a t

  (** Map a constructor name to a command-line string: downcase the name and convert [_] to
      [-]. *)
  val to_string_hum : 'a t -> 'a -> string

  val check_field_name : 'a t -> 'a -> (_, _, _) Field.t_with_perm -> unit
end

module type S = Command.Enumerable_sexpable
module type S_to_string = Command.Enumerable_stringable

module type Enum = sig
  module type S = S

  type 'a t = (module S with type t = 'a)

  include Single with type 'a t := 'a t

  val enum : 'a t -> (string * 'a) list
  val assert_alphabetic_order_exn : Source_code_position.t -> 'a t -> unit

  type ('a, 'b) make_param =
    ?case_sensitive:bool
    -> ?represent_choice_with:string
         (** If [represent_choice_with] is not passed, the documentation will be:

        {v
          -flag (choice1|choice2|...)     [doc]
        v}

        If there are many choices, this can cause this and other flags to have the
        documentation aligned very far to the right. To avoid that, the
        [represent_choice_with] flag can be passed as a shorter reference to the possible
        choices. Example:

        {v
          -flag CHOICE     [doc], CHOICE can be (choice1|choice2|...)
        v}

        [Command] does a much better job of aligning this.
    *)
    -> ?list_values_in_help:bool
    -> ?aliases:string list
    -> ?key:'a Univ_map.Multi.Key.t
    -> string
    -> doc:string
    -> 'a t
    -> 'b Command.Param.t

  val make_param : f:('a Command.Arg_type.t -> 'b Command.Flag.t) -> ('a, 'b) make_param

  val make_param_one_of_flags
    :  ?if_nothing_chosen:('a, 'a) Command.Param.If_nothing_chosen.t (** Default: Raise *)
    -> ?aliases:('a -> string list)
    -> doc:('a -> string)
    -> 'a t
    -> 'a Command.Param.t

  val make_param_optional_with_default_doc : default:'a -> ('a, 'a) make_param

  val make_param_optional_comma_separated
    :  ?allow_empty:bool
    -> ?strip_whitespace:bool
    -> ?unique_values:bool
    -> ('a, 'a list option) make_param

  val make_param_optional_comma_separated_with_default_doc
    :  ?allow_empty:bool
    -> ?strip_whitespace:bool
    -> ?unique_values:bool
    -> default:'a list
    -> ('a, 'a list) make_param

  val arg_type
    :  ?case_sensitive:bool
    -> ?key:'a Univ_map.Multi.Key.t
    -> ?list_values_in_help:bool
    -> 'a t
    -> 'a Command.Arg_type.t

  (** Transform a string to be accepted by [Command]. This is the transformation that is
      applied throughout this module.

      The transformations are:
      + Single quotes get removed (since it's annoying to have to quote them when running
      commands manually)
      + Underscores get turned into dashes (just to hopefully have a uniform convention
      between the two)
      + Other characters get lowercased

      Note that this is *not* actually a complete list of transformations needed to make
      an arbitrary string "command-friendly": for example, double quotes are left
      alone. This is because the expectation is that the string came from something like a
      [[@@deriving sexp]] on a variant type, and while single quotes can appear in ocaml
      variants, double quotes cannot. *)
  val command_friendly_name : string -> string

  (** Defines [to_string] and [of_string] functions for [M], based on [M.sexp_of_t] and
      [M.all]. The sexp representation of [M.t] must be a sexp atom. *)
  module Make_stringable (M : S) : Stringable.S with type t := M.t

  (** Defines an [of_string] function for [M], using [M.all] and [M.to_string]. Does not
      require [M] to be sexpable. *)
  module Make_of_string (M : S_to_string) : sig
    val of_string : String.t -> M.t
  end

  (** Defines [to_string] for [M], based on [M.sexp_of_t]. The sexp representation of
      [M.t] must be a sexp atom. *)
  module Make_to_string (M : Sexp_of) : sig
    val to_string : M.t -> String.t
  end

  module Single : sig
    module type S = Sexp_of

    type 'a t = (module S with type t = 'a)

    include Single with type 'a t := 'a t
  end
end
OCaml

Innovation. Community. Security.