From 4db1e51ab71e05bce1119c2c354b67c63fe6ae57 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Tue, 13 May 2014 19:31:15 -0400 Subject: [PATCH] fixup state transformer monad --- src/state-transformer.lfe | 10 ++++++---- test/unit/unit-state-transformer-tests.lfe | 15 +++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/state-transformer.lfe b/src/state-transformer.lfe index 7f83927..2f1659b 100644 --- a/src/state-transformer.lfe +++ b/src/state-transformer.lfe @@ -16,10 +16,10 @@ (lambda (_) (call inner-monad 'fail reason)))) (defun >>= - ((x f (tuple 'maybe-transformer inner-monad)) + ((x f (tuple 'state-transformer inner-monad)) (lambda (s) (call inner-monad '>>= - (funcall x f) + (funcall x s) (match-lambda (((tuple x1 s1)) (funcall (funcall f x1) s1))))))) (defun get (_) @@ -39,13 +39,15 @@ ((m s (tuple 'state-transformer inner-monad)) (call inner-monad '>>= (funcall m s) - (match-lambda (((tuple x s1)) x))))) + (match-lambda (((tuple x s1)) + (call inner-monad 'return x)))))) (defun exec ((m s (tuple 'state-transformer inner-monad)) (call inner-monad '>>= (funcall m s) - (match-lambda (((tuple x s1)) s1))))) + (match-lambda (((tuple x s1)) + (call inner-monad 'return s1)))))) (defun run ((m s (tuple 'state-transformer inner-monad)) diff --git a/test/unit/unit-state-transformer-tests.lfe b/test/unit/unit-state-transformer-tests.lfe index 859c3c9..abf65be 100644 --- a/test/unit/unit-state-transformer-tests.lfe +++ b/test/unit/unit-state-transformer-tests.lfe @@ -8,9 +8,6 @@ (include-lib "deps/lfeunit/include/lfeunit-macros.lfe") (include-lib "include/monads.lfe") -(deftestskip foo - (is 'false)) - (deftest eval (is-equal 5 (let* ((m (: state-transformer new 'identity-monad)) @@ -23,7 +20,7 @@ (mval (call m 'return 5))) (call m 'exec mval 'foo)))) -(deftest exec-double +(deftest exec-modify (is-equal 10 (let ((m (: state-transformer new 'identity-monad))) (call m 'exec @@ -31,6 +28,16 @@ (call m 'modify (lambda (x) (* x 2)))) 5)))) +(deftest exec-modify-multiple + (is-equal 30 + (let ((m (: state-transformer new 'identity-monad))) + (call m 'exec + (do-m m + (call m 'modify (lambda (x) (+ x 5))) + (call m 'modify (lambda (x) (* x 2))) + (call m 'return 123)) + 10)))) + (deftest exec-fail (is-throw #(error value) (let ((m (: state-transformer new 'identity-monad)))