From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: Monad code changes Date: Sat, 17 Jan 2015 23:56:29 +0100 Message-ID: <87mw5hdnj6.fsf@gnu.org> References: <877fwp3wph.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YCcIE-0004Iu-Rt for guix-devel@gnu.org; Sat, 17 Jan 2015 17:56:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YCcIB-0007wC-Ls for guix-devel@gnu.org; Sat, 17 Jan 2015 17:56:34 -0500 Received: from hera.aquilenet.fr ([2a01:474::1]:44137) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YCcIB-0007w8-EP for guix-devel@gnu.org; Sat, 17 Jan 2015 17:56:31 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 6BE0219D1 for ; Sat, 17 Jan 2015 23:56:30 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HTRGaSS1YEeT for ; Sat, 17 Jan 2015 23:56:30 +0100 (CET) Received: from pluto (reverse-83.fdn.fr [80.67.176.83]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 2205E1093 for ; Sat, 17 Jan 2015 23:56:30 +0100 (CET) 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") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Guix-devel Commit 81a9773 introduces a generic state monad in (guix monads), and the next commit makes =E2=80=98%store-monad=E2=80=99 an alias for =E2=80=98= %state-monad=E2=80=99. The nice thing is that =E2=80=98%state-monad=E2=80=99 remains low-overhead = thanks to the macro tricks=C2=B9 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 =3D (lambda (state) (values 1 2)) --8<---------------cut here---------------end--------------->8--- Feedback welcome! Ludo=E2=80=99. =C2=B9 http://lists.gnu.org/archive/html/guix-devel/2013-10/msg00034.html