guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Monad code changes


From: Ludovic Courtès
Subject: Re: Monad code changes
Date: Sat, 17 Jan 2015 23:56:29 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]