aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test.txt21
1 files changed, 18 insertions, 3 deletions
diff --git a/test.txt b/test.txt
index 072ac19..0fc86ab 100644
--- a/test.txt
+++ b/test.txt
@@ -1,10 +1,22 @@
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)
};
@@ -16,6 +28,9 @@ runParser p = case p of {
(.) f g x = f (g x);
id x = x;
-v = fmap id (Parser g);
-x = fmap ((.) f g) (Parser g);
-y = ((.) (fmap f) (fmap g)) (Parser g);
+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;