all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: "(" <paren@disroot.org>
Cc: 61214@debbugs.gnu.org
Subject: [bug#61214] [PATCH guix-artwork] website: posts: Add Dissecting Guix, Part 2: The Store Monad.
Date: Sun, 12 Feb 2023 19:05:43 +0100	[thread overview]
Message-ID: <87h6vqlpxk.fsf_-_@gnu.org> (raw)
In-Reply-To: <20230203073624.2338-1-paren@disroot.org> (paren@disroot.org's message of "Fri, 3 Feb 2023 07:36:24 +0000")

Hello!

"(" <paren@disroot.org> skribis:

> * website/posts/dissecting-guix-2-store-monad.md: New blog post.

Nice work again!  Some comments below:

> +In [the last post](https://guix.gnu.org/en/blog/2023/dissecting-guix-part-1-derivations/),
> +we briefly mentioned the `with-store` and `run-with-store` APIs.  Today, we'll
> +be looking at those in further detail, along with the related monad API and the
> +`%store-monad`!

Like Chris, I’m wary of acronyms (they can easily make things
impenetrable) so I’d write:

  - the `with-store` macro and the `run-with-store` procedure
  - the related monad interface

> +Monads are a little hard to explain, and from a distance, they seem more than a
> +bit confusing.  So, I want you to erase monads from your mind for now.  We'll
> +come back to them later.

I agree with Chris’s comment: a few sentences of a higher-level intro
showing where this fits in the big picture would be great!

It would be nice to stress, also, that one doesn’t _need_ to know about
monads to use the various programming interfaces of Guix; instead, it’s
a thing for someone who’d like to get a deep dive into the internals of
Guix.

I’m saying this because we FP people, especially in the Haskell camp,
are sometimes very good at making things look fancy and complicated.
The last thing we’d want is to make it sound like this whole thing
targets an audience of people with a PhD in the field.  :-)

> +# Yes, No, Maybe So
> +
> +Let's instead implement another M of functional programming, _`maybe`_ values,
> +representing a value that may or may not exist.  `maybe` is a very common
                                                  ^
Maybe add something like “For example, one might write a function that
divides two integers such that it returns special value `nothing` when
the divisor is zero, and `maybe 5` when passed `15` and `3`.”  (I
couldn’t think of a better example but you get the idea.  :-))

> +feature of strongly-typed functional languages, and you'll see it all over the

s/strongly/statically/  :-)

> +place in Haskell and OCaml code. However, Guile is dynamically typed, so we
> +usually use ad-hoc `#f`s and `'()`s for null values instead of a proper
> +"optional" value.

In Scheme we use #f, not '(), to denote “Nothing”.

> +# New Wheel, Old Wheel
> +
> +Now that we've reinvented the wheel, we'd better learn to use the original
> +wheel.  Guix provides a generic, high-level monads API, along with the two
> +generic monads `%identity-monad` and `%state-monad`, and the Guix-specific
> +`%store-monad`.  Since `maybe` is not one of them, let's integrate our version
> +into the Guix monad system!
> +
> +First we'll make the API available:

Maybe “First, let’s import that module:”?

> +```scheme
> +(use-modules (guix monads))
> +```
> +
> +To define a monad's API in Guix, we simply use the `define-monad` macro, and

“To define a monad in Guix, we use `define-monad`”

(In general, I’d avoid “simply” because whether it’s “simple” depends on
one’s background.)

> +`bind` is just the procedure that we use to compose monadic procedure calls
> +together, and `return` is the procedure that wraps values in the most basic form
> +of the monad.  A properly implemented `bind` and `return` must follow these
> +laws:

s/these laws/the so-called _monad laws_/

(since you use that term below)

> +;; First law: the left identity.
> +(equal? (maybe-chain (something 0)
> +                     mlaws-proc-1)
> +        (mlaws-proc-1 0))
> +;; #t

Should it be “⇒ #t” instead of “;; #t”, to follow the convention used in
the manual and in other places?

> +What have we learned about monads?  The key points we can take away are:
> +
> +1. Monads are a way of composing together procedures and values that are wrapped
> +   in containers that give them extra context, like `maybe` values.
> +2. Guix provides a high-level monad API that compensates for Guile's lack of

s/monad API/monad module/ (or “monad library”)

> +   strong types or an interface-like system.

“static types”?

> +3. This API provides the state monad, which allows you to thread state through

s/This API/The `(guix monads)` module/

> +   procedures such that you can pretend it doesn't exist.
> +4. Guix uses the store monad frequently to thread a store connection through
> +   procedures that need it.
> +5. The store monad is really just the state monad in disguise, where the state
> +   value is used to thread the store object through monadic procedures.
> +
> +If you've read this post in its entirety but still don't yet quite get it, don't
> +worry.  Try to modify and tinker about with the examples, and hopefully it will
> +all click eventually!

Maybe link to the “The Store Monad” section of the manual here or
earlier?

I feel we’re asking a lot of work from you, but hopefully the result
will be even more pleasant.  I guess v4 will be ready to go!

Thanks for all the work,
Ludo’.




  parent reply	other threads:[~2023-02-12 18:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-01 17:28 [bug#61214] [PATCH guix-artwork] website: posts: Add Dissecting Guix, Part 2: The Store Monad ( via Guix-patches via
2023-02-02  8:17 ` Simon Tournier
2023-02-02 13:06   ` ( via Guix-patches via
2023-02-02 15:00 ` [bug#61214] [PATCH guix-artwork v2] " ( via Guix-patches via
2023-02-02 15:04   ` ( via Guix-patches via
2023-02-06 15:38   ` Simon Tournier
2023-02-03  1:55 ` [bug#61214] run-with-state and run-with-store Feng Shu
2023-02-03  5:31   ` [bug#61214] [PATCH guix-artwork] website: posts: Add Dissecting Guix, Part 2: The Store Monad 宋文武 via Guix-patches via
2023-02-03  6:35   ` [bug#61214] run-with-state and run-with-store ( via Guix-patches via
2023-02-03  7:36 ` [bug#61214] [PATCH guix-artwork v3] website: posts: Add Dissecting Guix, Part 2: The Store Monad ( via Guix-patches via
2023-02-12 10:47   ` Christopher Baines
2023-02-12 14:17     ` ( via Guix-patches via
2023-02-13 12:08     ` zimoun
2023-02-12 18:05   ` Ludovic Courtès [this message]
2023-02-12 20:38     ` [bug#61214] [PATCH guix-artwork] " ( via Guix-patches via
2023-02-14  7:30 ` [bug#61214] [PATCH guix-artwork v4] " ( via Guix-patches via
2023-02-14  7:33 ` [bug#61214] [PATCH guix-artwork v5] " ( via Guix-patches via
2023-02-14 18:01   ` Simon Tournier
2023-02-14 19:26     ` ( via Guix-patches via
2023-02-16 17:00 ` [bug#61214] [PATCH guix-artwork v6] " ( via Guix-patches via
2023-02-20 21:23   ` Tobias Geerinckx-Rice via Guix-patches via
2023-02-20 22:04     ` ( via Guix-patches via

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h6vqlpxk.fsf_-_@gnu.org \
    --to=ludo@gnu.org \
    --cc=61214@debbugs.gnu.org \
    --cc=paren@disroot.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 external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.