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
|
pub trait Mode {
type Output<T>;
fn bind<T, F>(f: F) -> Self::Output<T>
where
F: FnOnce() -> T;
fn map<T, U, F>(t: Self::Output<T>, f: F) -> Self::Output<U>
where
F: FnOnce(T) -> U;
fn combine<T, U, V, F>(t: Self::Output<T>, u: Self::Output<U>, f: F) -> Self::Output<V>
where
F: FnOnce(T, U) -> V;
}
pub struct Emit;
impl Mode for Emit {
type Output<T> = T;
fn bind<T, F>(f: F) -> Self::Output<T>
where
F: FnOnce() -> T,
{
f()
}
fn map<T, U, F>(t: Self::Output<T>, f: F) -> Self::Output<U>
where
F: FnOnce(T) -> U,
{
f(t)
}
fn combine<T, U, V, F>(t: Self::Output<T>, u: Self::Output<U>, f: F) -> Self::Output<V>
where
F: FnOnce(T, U) -> V,
{
f(t, u)
}
}
pub struct Check;
impl Mode for Check {
type Output<T> = ();
fn bind<T, F>(_: F) -> Self::Output<T>
where
F: FnOnce() -> T,
{
}
fn map<T, U, F>(_: Self::Output<T>, _: F) -> Self::Output<U>
where
F: FnOnce(T) -> U,
{
}
fn combine<T, U, V, F>(_: Self::Output<T>, _: Self::Output<U>, _: F) -> Self::Output<V>
where
F: FnOnce(T, U) -> V,
{
}
}
|