aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--control/monad/state-minimal.scm8
1 files changed, 8 insertions, 0 deletions
diff --git a/control/monad/state-minimal.scm b/control/monad/state-minimal.scm
index 4fb40c2..aa7b1a0 100644
--- a/control/monad/state-minimal.scm
+++ b/control/monad/state-minimal.scm
@@ -11,30 +11,38 @@
;;; like the Haskell version (of MonadState). But obviously
;;; without all the nice syntax.
+;; newtype State = st-list -> st-list
+
+;; State
(define ((get) st-list)
"Sets the return value to the state value"
(match st-list
((v st)
(list st st))))
+;; v -> State
(define ((put v) st-list)
"Sets the state value to v, sets the return value to ()"
(list '() v))
+;; State -> (v -> State) -> State
(define ((bind st-proc proc) st-list)
(let ((new-st-list (st-proc st-list)))
(match new-st-list
((v _)
((proc v) new-st-list)))))
+;; State -> State -> State
(define ((then st-proc-1 st-proc-b) st-list-a)
(let ((st-list-b (st-proc-1 st-list-a)))
(st-proc-b st-list-b)))
+;; v -> State
(define ((return v) st-list)
"Sets the return value to v"
(cons v (cdr st-list)))
+;; State -> v -> (r v)
(define (run-state st-proc init)
"Exec state with init as starting state value"
(st-proc (list init init)))