unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Nikita Karetnikov <nikita@karetnikov.org>
Cc: guix-devel@gnu.org
Subject: Re: The store monad
Date: Wed, 02 Oct 2013 14:10:02 +0200	[thread overview]
Message-ID: <87bo376fhh.fsf@gnu.org> (raw)
In-Reply-To: <87k3hw2hie.fsf@karetnikov.org> (Nikita Karetnikov's message of "Wed, 02 Oct 2013 12:39:53 +0400")

Nikita Karetnikov <nikita@karetnikov.org> 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	other threads:[~2013-10-02 12:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-01 21:49 The store monad Ludovic Courtès
2013-10-02  8:39 ` Nikita Karetnikov
2013-10-02 12:10   ` Ludovic Courtès [this message]
2013-10-02 21:45 ` Ludovic Courtès
2013-10-03 21:15 ` Ludovic Courtès

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=87bo376fhh.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guix-devel@gnu.org \
    --cc=nikita@karetnikov.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).