summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-07-12 17:16:36 +0200
committerLudovic Courtès <ludo@gnu.org>2014-07-12 23:17:53 +0200
commitf62435e2868f5db15cc2f31300630c8ec873dd58 (patch)
tree4c48f36fafd1c02b5d65fb92fd257e3bd0c78dc0 /tests
parentc2150d9acece1dcaf54b3183254db4f83a992523 (diff)
downloadpatches-f62435e2868f5db15cc2f31300630c8ec873dd58.tar
patches-f62435e2868f5db15cc2f31300630c8ec873dd58.tar.gz
monads: Fix 'mapm' so that effects happen from left to right.
* guix/monads.scm (mapm): Don't reverse LST, so that items are processed from left to right. Bind the result of 'foldm' and reverse it. * tests/monads.scm ("sequence"): Change 'frob' so it performs its side effect within an 'mlet' body. Adjust call accordingly.
Diffstat (limited to 'tests')
-rw-r--r--tests/monads.scm14
1 files changed, 8 insertions, 6 deletions
diff --git a/tests/monads.scm b/tests/monads.scm
index 82f4b9989c..ac19d33f93 100644
--- a/tests/monads.scm
+++ b/tests/monads.scm
@@ -166,14 +166,16 @@
(let* ((input (iota 100))
(order '()))
(define (frob i)
- ;; The side effect here is used to keep track of the order in
- ;; which monadic values are bound.
- (set! order (cons i order))
- i)
+ (mlet monad ((foo (return 'foo)))
+ ;; The side effect here is used to keep track of the order in
+ ;; which monadic values are bound. Perform the side effect
+ ;; within a '>>=' so that it is performed when the return
+ ;; value is actually bound.
+ (set! order (cons i order))
+ (return i)))
(and (equal? input
- (run (sequence monad
- (map (lift1 frob monad) input))))
+ (run (sequence monad (map frob input))))
;; Make sure this is from left to right.
(equal? order (reverse input)))))