diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2015-06-08 22:49:50 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2015-06-08 23:00:49 +0200 |
| commit | 751630c9c3f7f3e87dfccc5f5ba8cf61cdd6f8fd (patch) | |
| tree | 2da2fcf7e6e300c98f2777e0bcb5670252ff4803 /doc | |
| parent | ae9b96c7846cc7d4528da5c6d861d6440cf46e33 (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.texi | 23 |
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}. | |||
| 2773 | Return a monadic value that encapsulates @var{val}. | 2773 | Return 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 |
| 2778 | procedure @var{mproc}@footnote{This operation is commonly referred to as | 2778 | procedures @var{mproc}@dots{}@footnote{This operation is commonly |
| 2779 | ``bind'', but that name denotes an unrelated procedure in Guile. Thus | 2779 | referred to as ``bind'', but that name denotes an unrelated procedure in |
| 2780 | we use this somewhat cryptic symbol inherited from the Haskell | 2780 | Guile. Thus we use this somewhat cryptic symbol inherited from the |
| 2781 | language.}. | 2781 | Haskell language.}. There can be one @var{mproc} or several of them, as |
| 2782 | in 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}) ...) @ |
