From: ludo@gnu.org (Ludovic Courtès)
To: Guix-devel <guix-devel@gnu.org>
Subject: Re: Monad code changes
Date: Sat, 17 Jan 2015 23:56:29 +0100 [thread overview]
Message-ID: <87mw5hdnj6.fsf@gnu.org> (raw)
In-Reply-To: <877fwp3wph.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Wed, 14 Jan 2015 21:59:22 +0100")
Commit 81a9773 introduces a generic state monad in (guix monads), and
the next commit makes ‘%store-monad’ an alias for ‘%state-monad’.
The nice thing is that ‘%state-monad’ remains low-overhead thanks to the
macro tricks¹ and the use of multiple-value returns to thread the state
across monadic procedure calls:
--8<---------------cut here---------------start------------->8---
scheme@(guix monads)> ,optimize (mlet* %state-monad ((x (set-current-state 0))
(y (set-current-state 1))
(p (set-current-state 2))
(z (return (+ y p))))
(return z))
$14 = (lambda (state) (values 1 2))
--8<---------------cut here---------------end--------------->8---
Feedback welcome!
Ludo’.
¹ http://lists.gnu.org/archive/html/guix-devel/2013-10/msg00034.html
prev parent reply other threads:[~2015-01-17 22:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-14 20:59 Monad code changes Ludovic Courtès
2015-01-17 22:56 ` Ludovic Courtès [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mw5hdnj6.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).