aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/fun
diff options
context:
space:
mode:
authorMarvin Borner2023-10-06 18:51:53 +0200
committerMarvin Borner2023-10-06 18:51:53 +0200
commite17ea13e7b94986af5d4b60ee6b83a34a0748249 (patch)
treea77880dd11e2e5cf437756a28a5e79925377b455 /samples/fun
parent6a451b6cad18a5b4ba60b6017dbfaa4ab707db8a (diff)
Fun with monads
Diffstat (limited to 'samples/fun')
-rw-r--r--samples/fun/jottary.bruijn25
1 files changed, 25 insertions, 0 deletions
diff --git a/samples/fun/jottary.bruijn b/samples/fun/jottary.bruijn
new file mode 100644
index 0000000..61ad048
--- /dev/null
+++ b/samples/fun/jottary.bruijn
@@ -0,0 +1,25 @@
+# a small Jottary (unary Jot) interpreter
+# also serves as example usage of monadic list operations
+# run with "printf 1...1 | bruijn jottary.bruijn"
+
+:import std/Combinator .
+:import std/List .
+:import std/Monad .
+:import std/Number .
+
+go [eval-r (<~>((concat huh) !! 0) ; i)]
+ huh (\replicate-m (l : {}r)) <$> (iterate ++‣ (+0))
+ l [(0 s) k]
+ r [s (k 0)]
+
+:test (go (+0)) (i)
+:test (go (+1)) ((i s) k)
+:test (go (+2)) (s (k i))
+:test (go (+3)) (i s k s k)
+:test (go (+4)) (s (k (i s k)))
+:test (go (+5)) (((s (k i)) s) k)
+:test (go (+6)) (s (k (s (k i))))
+:test (go (+59)) (k)
+:test (go (+503)) (s)
+
+main go ∘ length