package lsp

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

Source file monoid.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
module type Basic = Monoid_intf.Basic

module Make (M : Basic) : Monoid_intf.S with type t = M.t = struct
  include M

  module O = struct
    let ( @ ) = combine
  end

  let reduce = List.fold_left ~init:empty ~f:combine

  let map_reduce ~f =
    List.fold_left ~init:empty ~f:(fun acc a -> combine acc (f a))
end
[@@inlined always]

module Exists = Make (struct
  type t = bool

  let empty = false

  let combine = ( || )
end)

module Forall = Make (struct
  type t = bool

  let empty = true

  let combine = ( && )
end)

module String = Make (struct
  type t = string

  let empty = ""

  let combine = ( ^ )
end)

module List (M : sig
  type t
end) : Monoid_intf.S with type t = M.t list = Make (struct
  type t = M.t list

  let empty = []

  let combine = ( @ )
end)

module Appendable_list (M : sig
  type t
end) : Monoid_intf.S with type t = M.t Appendable_list.t = Make (struct
  type t = M.t Appendable_list.t

  let empty = Appendable_list.empty

  let combine = Appendable_list.( @ )
end)

module Unit : Monoid_intf.S with type t = Unit.t = Make (struct
  include Unit

  let empty = ()

  let combine () () = ()
end)

module Add (M : sig
  type t

  val zero : t

  val ( + ) : t -> t -> t
end) : Monoid_intf.S with type t = M.t = Make (struct
  include M

  let empty = zero

  let combine = ( + )
end)

module Mul (M : sig
  type t

  val one : t

  val ( * ) : t -> t -> t
end) : Monoid_intf.S with type t = M.t = Make (struct
  include M

  let empty = one

  let combine = ( * )
end)

module Union (M : sig
  type t

  val empty : t

  val union : t -> t -> t
end) : Monoid_intf.S with type t = M.t = Make (struct
  include M

  let combine = union
end)

module Product (A : Monoid_intf.Basic) (B : Monoid_intf.Basic) :
  Monoid_intf.S with type t = A.t * B.t = Make (struct
  type t = A.t * B.t

  let empty = (A.empty, B.empty)

  let combine (a1, b1) (a2, b2) = (A.combine a1 a2, B.combine b1 b2)
end)

module Product3
    (A : Monoid_intf.Basic)
    (B : Monoid_intf.Basic)
    (C : Monoid_intf.Basic) : Monoid_intf.S with type t = A.t * B.t * C.t =
Make (struct
  type t = A.t * B.t * C.t

  let empty = (A.empty, B.empty, C.empty)

  let combine (a1, b1, c1) (a2, b2, c2) =
    (A.combine a1 a2, B.combine b1 b2, C.combine c1 c2)
end)

module Function (A : sig
  type t
end)
(M : Monoid_intf.Basic) : Monoid_intf.S with type t = A.t -> M.t = Make (struct
  type t = A.t -> M.t

  let empty _ = M.empty

  let combine f g x = M.combine (f x) (g x)
end)

module Endofunction (A : sig
  type t
end) : Monoid_intf.S with type t = A.t -> A.t = Make (struct
  type t = A.t -> A.t

  let empty x = x

  let combine f g x = f (g x)
end)
OCaml

Innovation. Community. Security.