guix-devel
[Top][All Lists]
Advanced

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

Re: The store monad


From: Ludovic Courtès
Subject: Re: The store monad
Date: Wed, 02 Oct 2013 14:10:02 +0200
User-agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux)

Nikita Karetnikov <address@hidden> skribis:

> Thanks, this is definitely a step in the right direction.
>
>> That’s the first time I use monads after just reading about it.
>
> I hope that you checked the monad laws.

Left identity:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(guix monads)
scheme@(guile-user)> (store-bind (store-return 2) (lambda (x) (store-return (pk 
'x x))))
$1 = #<procedure 272e600 at guix/monads.scm:209:2 (store)>
scheme@(guile-user)> ($1 #f)

;;; (x 2)
$2 = 2
--8<---------------cut here---------------end--------------->8---

Right identity:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (store-bind (store-return 2) store-return)
$3 = #<procedure 26d8960 at guix/monads.scm:209:2 (store)>
scheme@(guile-user)> ($3 #f)
$4 = 2
--8<---------------cut here---------------end--------------->8---

Associativity:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (define (f x) (store-return (+ 1 x)))
scheme@(guile-user)> (define (g x) (store-return (* 2 x)))
scheme@(guile-user)> (store-bind (store-bind (store-return 0) f) g)
$5 = #<procedure 2766210 at guix/monads.scm:209:2 (store)>
scheme@(guile-user)> ($5 #f)
$6 = 2
scheme@(guile-user)> (store-bind (store-return 0) (lambda (x) (store-bind (f x) 
g)))
$7 = #<procedure 283a9c0 at guix/monads.scm:209:2 (store)>
scheme@(guile-user)> ($7 #t)
$8 = 2
--8<---------------cut here---------------end--------------->8---

Seems to be lawful and everything.  ;-)

I’ll add that to the tests.

Thanks,
Ludo’.



reply via email to

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