-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fantasy_land_traits.gleam
83 lines (62 loc) · 1.37 KB
/
fantasy_land_traits.gleam
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
pub trait Setoid {
fn equals(Self, Self) -> Bool
}
pub trait Ord {
fn less_than_equal(Self, Self) -> Bool
}
pub trait Semigroup {
fn concat(Self, Self) -> Self
}
pub trait Monoid: Semigroup {
fn empty() -> Self
}
pub trait Group: Monoid {
fn invert(Self) -> Self
}
pub trait Semigroupoid {
fn compose(Self(i, j), Self(j, k)) -> Self(i, k)
}
pub trait Category: Semigroupoid {
fn id() -> Self(i, k)
}
pub trait Filterable {
fn filter(Self(a), fn(a) -> Bool) -> Self(a)
}
pub trait Functor {
fn map(Self(a), fn(a) -> b) -> Self(b)
}
pub trait Contravariant {
fn contramap(Self(b), fn(a) -> b) -> Self(a)
}
pub trait Apply: Functor {
fn ap(Self(fn(a) -> b), Self(a)) -> Self(b)
}
pub trait Apply {
fn ap(Self(fn(a) -> b), Self(a)) -> Self(b)
}
pub trait Applicative: Apply {
fn of(a) -> Self(a)
}
pub trait Alt: Functor {
fn alt(Self(a), Self(a)) -> Self(a)
}
pub trait Plus: Alt {
fn zero() -> Self(a)
}
pub trait Alternative: Applicative + Plus
pub trait Chain: Apply {
fn chain(Self(a), fn(a) -> Self(b)) -> Self(b)
}
pub trait Monad: Applicative + Self + Chain
pub trait Foldable {
fn reduce(Self(b), a, fn(a) -> b) -> b
}
pub trait Extend: Functor {
fn extend(Self(a), fn(Self(a)) -> a) -> Self(b)
}
pub trait Comonad: Extend {
fn extract(Self(a)) -> a
}
pub trait Traversable {
fn traverse(Self(a), Applicative(u), u(b)) -> u(Self(b))
}