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