package core

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

Source file bool.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
open! Import

type t = bool [@@deriving bin_io, typerep]

include
  Identifiable.Extend
    (Base.Bool)
    (struct
      type nonrec t = t [@@deriving bin_io]
    end)

module Replace_polymorphic_compare = Base.Bool

include (
  Base.Bool :
    module type of struct
    include Base.Bool
  end
  with type t := t)

include Comparable.Validate (Base.Bool)

let of_string_hum =
  let table =
    lazy
      (let table = String.Caseless.Table.create () in
       [ false, [ "false"; "no"; "0" ]; true, [ "true"; "yes"; "1" ] ]
       |> List.iter ~f:(fun (bool, strings) ->
         List.iter strings ~f:(fun string ->
           Hashtbl.set table ~key:string ~data:bool;
           Hashtbl.set table ~key:(String.prefix string 1) ~data:bool));
       table)
  in
  let raise_invalid input =
    let expected_case_insensitive = String.Set.of_list (Hashtbl.keys (force table)) in
    raise_s
      [%message
        "Bool.of_string_hum: invalid input"
          (input : string)
          (expected_case_insensitive : String.Set.t)]
  in
  fun string ->
    Hashtbl.find_and_call (force table) string ~if_found:Fn.id ~if_not_found:raise_invalid
;;

let quickcheck_generator = Base_quickcheck.Generator.bool
let quickcheck_observer = Base_quickcheck.Observer.bool
let quickcheck_shrinker = Base_quickcheck.Shrinker.bool

module Stable = struct
  module V1 = struct
    type nonrec t = t [@@deriving compare, sexp, bin_io]
  end
end
OCaml

Innovation. Community. Security.