-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.nix
More file actions
64 lines (54 loc) · 1.14 KB
/
Copy pathtest.nix
File metadata and controls
64 lines (54 loc) · 1.14 KB
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
let
pkgs = import <nixpkgs> {};
lm =
{
mempty = [];
mappend = a: b: a ++ b;
};
RW = import ./lib/rw.nix lm;
test = e: c:
let
expected = e 7;
computed = c 7;
in
{
inherit expected computed;
res = expected == computed;
};
f = x: x + 1;
g = x: 2 * x;
gf = d g f;
h = xs: xs ++ [8];
i = xs: [9] ++ xs;
hi = d h i;
d = s: t: x: s (t x);
in
with RW;
{
functor =
{
id = test (fmap (x: x) (pure 2)) (pure 2);
comp = test (fmap (x: g (f x)) (pure 2)) (fmap g (fmap f (pure 2)));
};
applicative =
{
homo = test (ap (pure f) (pure 2)) (pure (f 2));
comp = test
(ap (ap (ap (pure d) (pure f)) (pure g)) (pure 2))
(ap (pure f) (ap (pure g) (pure 2)));
};
writer =
{
emptyIdentity = test (rap (tell [1]) (pure null)) (rap (pure null) (tell [1]));
tellTwice = test (rap (tell [1]) (tell [2])) (tell [1 2]);
censorComp = test (censor h (censor i (tell [2]))) (censor hi (tell [2]));
};
reader =
{
localComp = test (local f (local g get)) (local gf get);
};
fix =
{
onlyTell = test (_: pkgs.lib.fix (tell [2])) (tell [2]);
};
}