diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2018-11-13 00:18:31 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2018-11-13 00:18:31 +0100 |
commit | b282f1a92137e2104b96186d05ff6e543eafdf2a (patch) | |
tree | 640fccea6bf74c0027561afeb8b510830404ffce /control/monad/state.scm | |
parent | Introduce define-stateful macro. (diff) | |
download | scheme-monad-b282f1a92137e2104b96186d05ff6e543eafdf2a.tar.gz scheme-monad-b282f1a92137e2104b96186d05ff6e543eafdf2a.tar.xz |
run-state, >>=, and >> now correctly defined for <state>.
Diffstat (limited to 'control/monad/state.scm')
-rw-r--r-- | control/monad/state.scm | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/control/monad/state.scm b/control/monad/state.scm index a8e7775..3ebdcc6 100644 --- a/control/monad/state.scm +++ b/control/monad/state.scm @@ -29,16 +29,18 @@ (make <state> #:proc proc)) (define-method (>>= (st <state>) f) - (lambda (st-list) - (let ((new-st-list ((proc st) st-list))) - (match new-st-list - ((v _) - ((proc (f v)) new-st-list)))))) + (make-state + (lambda (st-list) + (let ((new-st-list ((proc st) st-list))) + (match new-st-list + ((v _) + ((proc (f v)) new-st-list))))))) (define-method (>> (a <state>) (b <state>)) - (lambda (st-list-a) - (let ((st-list-b ((proc a) st-list-a))) - ((proc b) st-list-b)))) + (make-state + (lambda (st-list-a) + (let ((st-list-b ((proc a) st-list-a))) + ((proc b) st-list-b))))) (define-syntax define-stateful (syntax-rules () @@ -61,7 +63,7 @@ "Sets st to v." (list '() v)) -(define-method (run-state st-proc init) +(define-method (run-state (st <state>) init) "Exec state with init as starting state value and st." - (st-proc (list init init))) + ((proc st) (list init init))) |