aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2019-04-09 23:36:56 +0200
committerTom Smeding <tom.smeding@gmail.com>2019-04-09 23:36:56 +0200
commit8a3653d8f30f7d0f79556f464ea781472a931b2e (patch)
treebed905083a069996e7f5f979abf288a2e3b5d4c0
parent573967434a8b1cb14ee7de43ec11bd616cf568c6 (diff)
test.txt: Add apply and pure
-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;