-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMonoid.re
42 lines (36 loc) · 798 Bytes
/
Monoid.re
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
module type Monoid = {
type t;
open Semigroup;
include Semigroup with type t := t;
let empty: t;
};
module MonoidUtils = (M: Monoid) => {
include M;
let (<+>) = (x, y) => append(x, y);
let concat = xs => List.fold_left((<+>), empty, xs);
};
module StringM_: Monoid with type t = string = {
include Semigroup.StringSemigroup;
let empty = "";
};
module StringMonoid = MonoidUtils(StringM_);
module type GenericTypeConstuctor = {type t;};
module ListM_ = (T: GenericTypeConstuctor) : (Monoid with type t = list(T.t)) => {
include
Semigroup.ListSemigroup(
{
type t = T.t;
},
);
let empty = [];
};
module ListMonoid = (T: GenericTypeConstuctor) =>
MonoidUtils(
(
ListM_(
{
type t = T.t;
},
)
),
);