aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-10-08 23:35:08 +0200
committerLudovic Courtès <ludo@gnu.org>2014-10-08 23:35:20 +0200
commit405a9d4ec9806993a6453f0dfba78fc65d5e7993 (patch)
tree83096b186be61f0a0daca3b808ab2aeb58bfb352 /guix
parent2e1bafb03438757c7cc34c16230b00623507ff84 (diff)
downloadgnu-guix-405a9d4ec9806993a6453f0dfba78fc65d5e7993.tar
gnu-guix-405a9d4ec9806993a6453f0dfba78fc65d5e7993.tar.gz
monads: Add 'mbegin'.
* guix/monads.scm (mbegin): New macro. * tests/monads.scm ("mbegin"): New test. * doc/guix.texi (The Store Monad): Document it.
Diffstat (limited to 'guix')
-rw-r--r--guix/monads.scm14
1 files changed, 14 insertions, 0 deletions
diff --git a/guix/monads.scm b/guix/monads.scm
index 2ab3fb94f0..d9580a7f8e 100644
--- a/guix/monads.scm
+++ b/guix/monads.scm
@@ -38,6 +38,7 @@
with-monad
mlet
mlet*
+ mbegin
lift1 lift2 lift3 lift4 lift5 lift6 lift7 lift
listm
foldm
@@ -171,6 +172,19 @@ form is (VAR -> VAL), bind VAR to the non-monadic value VAL in the same way as
(let ((var temp) ...)
body ...)))))))
+(define-syntax mbegin
+ (syntax-rules ()
+ "Bind the given monadic expressions in sequence, returning the result of
+the last one."
+ ((_ monad mexp)
+ (with-monad monad
+ mexp))
+ ((_ monad mexp rest ...)
+ (with-monad monad
+ (>>= mexp
+ (lambda (unused-value)
+ (mbegin monad rest ...)))))))
+
(define-syntax define-lift
(syntax-rules ()
((_ liftn (args ...))