blob: 0fc86ab4d3c2a78397b36ad24db9c15444c038a0 (
plain)
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
|
fmap f p = Parser ((.) (fmapEither (fmap1st f)) (runParser p));
pure x = Parser (\s -> Right (x, s));
apply pf px = Parser (\s ->
bindEither (runParser pf s) (\res1 -> case res1 of {
(f, s') -> bindEither (runParser px s') (\res2 -> case res2 of {
(x, s'') -> Right (f x, s'')
})}));
fmapEither f e = case e of {
Left x -> Left x;
Right x -> Right (f x)
};
bindEither m f = case m of {
Left x -> Left x;
Right x -> f x
};
fmap1st f p = case p of {
(l, r) -> (f l, r)
};
runParser p = case p of {
Parser g -> g
};
(.) f g x = f (g x);
id x = x;
fl1_a = fmap id (Parser g);
fl1_b = Parser g;
fl2_a = fmap ((.) f g) (Parser g);
fl2_b = ((.) (fmap f) (fmap g)) (Parser g);
al1_a = apply (pure id) v;
al1_b = v;
|