aboutsummaryrefslogtreecommitdiff
path: root/test2.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test2.lux28
1 files changed, 19 insertions, 9 deletions
diff --git a/test2.lux b/test2.lux
index 15bcecdbc..d036bbde4 100644
--- a/test2.lux
+++ b/test2.lux
@@ -388,15 +388,6 @@
(lambda [state]
(#Ok [state state])))
-(def monadic-dup
- (exec [foo get-state
- bar get-state
- baz (return 1000)]
- (return (+ (+ foo bar) baz))))
-
-(def (run-state monad state)
- (monad state))
-
(def list-map #Nil)
(def (put key val map)
@@ -424,6 +415,25 @@
[?key ?val]
(fold concat "" (list "#" ?key " " (show ?val)))))
+(def (within slot monad)
+ (lambda [state]
+ (let =return (monad (get slot state))
+ (case =return
+ (#Ok ?state ?value)
+ (#Ok (put slot ?state state) ?value)
+
+ _
+ =return))))
+
+(def monadic-dup
+ (exec [foo get-state
+ bar get-state
+ baz (return 1000)]
+ (return (+ (+ foo bar) baz))))
+
+(def (run-state monad state)
+ (monad state))
+
(def (interpose elem list)
(case list
(#Cons x (#Cons y list'))