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
module Core_over_semigroup
(S : Preface_specs.SEMIGROUP)
(M : Preface_specs.Monoid.WITH_NEUTRAL with type t = S.t) :
Preface_specs.Monoid.CORE with type t = M.t = struct
include S
let neutral = M.neutral
end
module Core (Req : Preface_specs.Monoid.WITH_NEUTRAL_AND_COMBINE) :
Preface_specs.Monoid.CORE with type t = Req.t =
Req
module Operation (Core : Preface_specs.Monoid.CORE) :
Preface_specs.Monoid.OPERATION with type t = Core.t = struct
include Semigroup.Operation (Core)
let reduce list = Preface_core.Monoid.reduce Core.combine Core.neutral list
end
module Infix (Core : Preface_specs.Monoid.CORE) :
Preface_specs.Monoid.INFIX with type t = Core.t = struct
include Semigroup.Infix (Core)
end
module Via
(Core : Preface_specs.Monoid.CORE)
(Operation : Preface_specs.Monoid.OPERATION with type t = Core.t)
(Infix : Preface_specs.Monoid.INFIX with type t = Operation.t) :
Preface_specs.MONOID with type t = Infix.t = struct
include Core
include Operation
module Infix = Infix
include Infix
end
module Via_combine_and_neutral
(Req : Preface_specs.Monoid.WITH_NEUTRAL_AND_COMBINE) :
Preface_specs.MONOID with type t = Req.t = struct
module Core = Core (Req)
include Core
module Operation = Operation (Core)
module Infix = Infix (Core)
include Operation
include Infix
end
module Over_semigroup
(S : Preface_specs.SEMIGROUP)
(M : Preface_specs.Monoid.WITH_NEUTRAL with type t = S.t) :
Preface_specs.MONOID with type t = S.t = struct
module Core = Core_over_semigroup (S) (M)
module Operation = Operation (Core)
module Infix = Infix (Core)
include Core
include Operation
include Infix
end
module From_alternative
(Alternative : Preface_specs.ALTERNATIVE)
(T : Preface_specs.Types.T0) :
Preface_specs.MONOID with type t = T.t Alternative.t =
Via_combine_and_neutral (struct
type t = T.t Alternative.t
let combine = Alternative.combine
let neutral = Alternative.neutral
end)
module From_monad_plus
(Monad_plus : Preface_specs.MONAD_PLUS)
(T : Preface_specs.Types.T0) :
Preface_specs.MONOID with type t = T.t Monad_plus.t =
Via_combine_and_neutral (struct
type t = T.t Monad_plus.t
let combine = Monad_plus.combine
let neutral = Monad_plus.neutral
end)