summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-06-08 22:49:50 +0200
committerLudovic Courtès <ludo@gnu.org>2015-06-08 23:00:49 +0200
commit751630c9c3f7f3e87dfccc5f5ba8cf61cdd6f8fd (patch)
tree2da2fcf7e6e300c98f2777e0bcb5670252ff4803 /doc
parentae9b96c7846cc7d4528da5c6d861d6440cf46e33 (diff)
monads: Allow n-ary '>>=' expressions.
Suggested by Federico Beffa <beffa@fbengineering.ch>. * guix/monads.scm (bind-syntax): New macro. (with-monad): Use it instead of 'identifier-syntax'. * tests/monads.scm (">>= with more than two arguments"): New test. * doc/guix.texi (The Store Monad): Explain that there can be several MPROC. Add an example.
Diffstat (limited to 'doc')
-rw-r--r--doc/guix.texi23
1 files changed, 18 insertions, 5 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index bcfa52d5b11..85ccd4057e6 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2773,12 +2773,25 @@ in @var{monad}.
2773Return a monadic value that encapsulates @var{val}. 2773Return a monadic value that encapsulates @var{val}.
2774@end deffn 2774@end deffn
2775 2775
2776@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} 2776@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
2777@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic 2777@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
2778procedure @var{mproc}@footnote{This operation is commonly referred to as 2778procedures @var{mproc}@dots{}@footnote{This operation is commonly
2779``bind'', but that name denotes an unrelated procedure in Guile. Thus 2779referred to as ``bind'', but that name denotes an unrelated procedure in
2780we use this somewhat cryptic symbol inherited from the Haskell 2780Guile. Thus we use this somewhat cryptic symbol inherited from the
2781language.}. 2781Haskell language.}. There can be one @var{mproc} or several of them, as
2782in this example:
2783
2784@example
2785(run-with-state
2786 (with-monad %state-monad
2787 (>>= (return 1)
2788 (lambda (x) (return (+ 1 x)))
2789 (lambda (x) (return (* 2 x)))))
2790 'some-state)
2791
2792@result{} 4
2793@result{} some-state
2794@end example
2782@end deffn 2795@end deffn
2783 2796
2784@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @ 2797@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @