diff options
author | Ludovic Courtès <ludo@gnu.org> | 2014-07-12 17:16:36 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2014-07-12 23:17:53 +0200 |
commit | f62435e2868f5db15cc2f31300630c8ec873dd58 (patch) | |
tree | 4c48f36fafd1c02b5d65fb92fd257e3bd0c78dc0 /guix | |
parent | c2150d9acece1dcaf54b3183254db4f83a992523 (diff) | |
download | gnu-guix-f62435e2868f5db15cc2f31300630c8ec873dd58.tar gnu-guix-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 'guix')
-rw-r--r-- | guix/monads.scm | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/guix/monads.scm b/guix/monads.scm index ec2b7f8b3b..c2c6f1a03d 100644 --- a/guix/monads.scm +++ b/guix/monads.scm @@ -209,13 +209,15 @@ monadic value seeded by INIT." (define (mapm monad mproc lst) "Map MPROC over LST, a list of monadic values in MONAD, and return a monadic -list." - (foldm monad - (lambda (item result) - (mlet monad ((item (mproc item))) - (return (cons item result)))) - '() - (reverse lst))) +list. LST items are bound from left to right, so effects in MONAD are known +to happen in that order." + (mlet monad ((result (foldm monad + (lambda (item result) + (mlet monad ((item (mproc item))) + (return (cons item result)))) + '() + lst))) + (return (reverse result)))) (define-inlinable (sequence monad lst) "Turn the list of monadic values LST into a monadic list of values, by |