From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id QBVsES316GNl3wAAbAwnHQ (envelope-from ) for ; Sun, 12 Feb 2023 15:18:21 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id oEB3ES316GOznwAA9RJhRA (envelope-from ) for ; Sun, 12 Feb 2023 15:18:21 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A15331E87C for ; Sun, 12 Feb 2023 15:18:20 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRDB6-0005Gy-8m; Sun, 12 Feb 2023 09:18:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRDB4-0005Gj-Dw for guix-patches@gnu.org; Sun, 12 Feb 2023 09:18:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pRDB3-0004oU-WE for guix-patches@gnu.org; Sun, 12 Feb 2023 09:18:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pRDB3-0005Y0-QI for guix-patches@gnu.org; Sun, 12 Feb 2023 09:18:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#61214] [PATCH guix-artwork v3] website: posts: Add Dissecting Guix, Part 2: The Store Monad. Resent-From: "(" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 12 Feb 2023 14:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61214 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: "Christopher Baines" Cc: 61214@debbugs.gnu.org X-Debbugs-Original-Cc: 61214@debbugs.gnu.org, guix-patches@gnu.org Received: via spool by 61214-submit@debbugs.gnu.org id=B61214.167621147721315 (code B ref 61214); Sun, 12 Feb 2023 14:18:01 +0000 Received: (at 61214) by debbugs.gnu.org; 12 Feb 2023 14:17:57 +0000 Received: from localhost ([127.0.0.1]:44418 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pRDAz-0005Xh-CH for submit@debbugs.gnu.org; Sun, 12 Feb 2023 09:17:57 -0500 Received: from knopi.disroot.org ([178.21.23.139]:52922) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pRDAx-0005XV-0a for 61214@debbugs.gnu.org; Sun, 12 Feb 2023 09:17:56 -0500 Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 42BCF41327; Sun, 12 Feb 2023 15:17:53 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f7ZqqsuFBiPI; Sun, 12 Feb 2023 15:17:52 +0100 (CET) Content-Type: multipart/signed; boundary=5cc3f916ba10d364804d18b296b0a5302a012e9f7cd33632812b60b82ee4; micalg=pgp-sha512; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1676211471; bh=E28h6ps1mZAzT5JXFkJnADrEGRugC/ZLuHObznvjNk8=; h=Date:Cc:Subject:From:To:References:In-Reply-To; b=XrhAnoVtLV/bvfpAHKJHD8VzA/fcMH4YF92L6oOsIscKdkzRipLbMz+VZCqeTIlEO 3xYYhfOpp9P+OzesTZeavFtUdgiyZ3Ny8j9OLYoRLJmmlIVW2ROSxgGb9yoC3OgV2d XtGE0HfD08NToVJ2Kgut/MI/KNZMesrMWOFU1TqUzZkRYDGurKCUmCPUJaH+FHEH9Z nz+i4sGaxr97HZMx7brje7t2HXILLJEyYdbUSyXbijjzZZBHKQJ3lbVMAmRgfJNyN5 JX+usfAO2whf+DPeZkvRLaC6MWvFlBqk69F9KPQEUuOu42hEPXQ/NIZivTZfGsQEPQ GuqngqnSEm9jg== Date: Sun, 12 Feb 2023 14:17:47 +0000 Message-Id: References: <20230201172821.3072-1-paren@disroot.org> <20230203073624.2338-1-paren@disroot.org> <875yc73xgu.fsf@cbaines.net> In-Reply-To: <875yc73xgu.fsf@cbaines.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "\(" X-ACL-Warn: , "\( via Guix-patches" From: "\( via Guix-patches" via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=XrhAnoVt; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1676211501; a=rsa-sha256; cv=none; b=CAfnQ3CG6MhFSD0yfKh4PXPAAgPHVUoZaqfOkiYr2HiK+hQAosUmhOypiZSkqsOBTDaYTB RBkni7obJbBEoaXW/70mkMuOpLOusbANPYM13o+PKUlq33rT47QFE7MWcNwSLTls4uGQMc wBrX+6PzSNIcBhHV73oZutAsqTzUExFbcneIAuFhVwa7xVcAAR5Ii+IpQYwEQZWoBdzOVj 6du8YDWpsNfwt9gQqOKmSUU5sv72puaxnlQXPiRzg/VgN6GCx8KvcnESMm4oWy6JLJnBsn zvb2G35/wfde0JqS7AyK3pPsd0y/+Kuor3ecfRMUoQvGG0sPH/8BpvktcaL0yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1676211501; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:content-type:content-type:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=D4K7CyYXSNj2bcKsjDEk0SYIUW+uytDFMjoxSxdxjiY=; b=kRt0p5xeR9Ci83yvj3nbcaDUN/pJAah1d/+KyGAUbp72WW5/5oO1ke3hARZUWpLk0LP1cH hSDzURi+QBjyUbhzSXLuitceZQDotObaCA/Q3Dv08H252ijwkjMaAEbroQNFSMcbTqcxHU b8vyk0E9RF1WPVJKk1frIb6/BF2VjfJ+q1jDwofLOiM6iEDTguBKIDtdnJOpVUHFtpX+FW JXaHBfVDs2dt9/9DOiHB5BrbGI5igolp22jKgijmc8p9DXSRbbQDA3Tskn7JQa4XhDg+NG ugYnSnGQ+l3YYvf4JktMWSuYhielnic/DZBbPKAaeYHYiVL2iONaxPWOWINotg== X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -3.22 X-Spam-Score: -3.22 X-Migadu-Queue-Id: A15331E87C Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=disroot.org header.s=mail header.b=XrhAnoVt; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org X-TUID: qtPVwYUG5uem --5cc3f916ba10d364804d18b296b0a5302a012e9f7cd33632812b60b82ee4 Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Hi, On Sun Feb 12, 2023 at 10:47 AM GMT, Christopher Baines wrote: > I think there's some room to improve the introduction here. Linking to > the previous post in the series is fine, but what I think is missing is > some context around the topic and setting some expectations for the > reader. > I'm not sure who you're pitching this post at People who have used Guix and know basic Scheme but haven't delved into Gui= x's interiors yet :) > I think the s's after the `#f` and `'()` here don't aid > readability. Something like: Fair. > I think it would be clearer to say "To define the maybe monad, we use > the define-monad macro.", then there's no need to keep track of what API > is being discussed. I'm also not sure it's useful to talk about things > within Guix as APIs unless you're talking about a specific case of using > Guix from some external program/software. Good point. Maybe I could say something like: "To define the maybe monad's behaviour, we use the define-monad macro." using "behaviour" to describe the specifics of a monad. > I think this would be confusing for someone who's encountering monads > for the first time. I think it's good to try and avoid going to deep, > but if there's mention of the "laws", I think it's important to say that > these laws come from category theory. Yeah, okay. > > + > > +```scheme > > +(mbegin %maybe-monad > > + (remove-a "abc")) > > +;; #< is?: #t value: "bc"> > > +``` > > This is stretching my understanding of monads here, but would this > example be better if the (mbegin bit included two expressions rather > than one? I might just remove the MBEGIN example entirely. I have no idea why MBEGIN= exists, or what advantages it confers, so I just included it for the sake of comple= teness -.o.- If someone could elaborate on what MBEGIN is for I would very much a= ppreciate it. > I think the point is still good here, but maybe it's simpler to say "but > why does Guix use monads?". Okay. > > +So, when we do `(run-with-state result (list 32))`, we're passing `(li= st 32)` as > > +the initial state value, and then the `>>=3D` form passes that and `33= ` to > > +`state-push`. What `%state-monad` allows us to do is thread together = some > > +procedures that require some kind of state, while pretending the state= isn't > > +there, and then retrieve both the final state and the result at the en= d! > > I'm not sure the "pretending the state isn't there" but is helpful here, > if you're pretending the state doesn't exist, why is writing monadic > code helpful? Yeah, this doesn't really get across the point I'm trying to make. I'm not= sure how else to word it, though... > > +We mentioned that, technically, we didn't need monads for Guix. Indee= d, many > > +(now deprecated) procedures take a store value as the argument, such a= s > > +`build-expression->derivation`. However, using monads both helps ensu= re purity > > +and simply looks nicer. > > I'm not sure what you mean by purity here? Me neither :P Simon mentioned something about monads ensuring purity in th= eir review, which I didn't quite understand, so I just wrote something vague ab= out it (which I shouldn't have done). > > +And indeed, it symlinks the `irssi` binary to the output path. Some o= ther, > > +higher-level, monadic procedures include `interned-file`, which copies= a file > > +from outside the store into it, and `text-file`, which copies some tex= t into it. > > +Generally, these procedures aren't used, as there are higher-level pro= cedures > > +that perform similar functions (which we will discuss later), but for = the sake > > +of this blog post, here's an example: > > + > > +```scheme > > +(with-store store > > + (run-with-store store > > + (text-file "unmatched-paren" > > + "( "))) > > +;; "/gnu/store/v6smacxvdk4yvaa3s3wmd54lixn1dp3y-unmatched-paren" > > +``` > > I think the build up to this section is pretty good, but then I'm not > sure what this last section is trying to explain. It's just showing an example of the TEXT-FILE procedure, that's all :) > Maybe at this point it would be good to leave the REPL and give some > concrete examples of non-trivial monadic code in Guix, and discuss what > that would look like if implemented without using monads. Good idea! :) > > +# Conclusion > > + > > +What have we learned about monads? The key points we can take away ar= e: > > + > > +1. Monads are a way of composing together procedures and values that a= re wrapped > > + in containers that give them extra context, like `maybe` values. > > +2. Guix provides a high-level monad API that compensates for Guile's l= ack of > > + strong types or an interface-like system. > > I'd say that Guile is a strongly typed language. I'm also not sure what > the point about compensating for something lacking in Guile means. Guile doesn't have type definitions and it can't "fix" values to types. I'= d consider that to be weak typing, personally :) Regarding the point: it's supposed to say something like > > +4. Guix uses the store monad frequently to thread a store connection t= hrough > > + procedures that need it. > > +5. The store monad is really just the state monad in disguise, where t= he state > > + value is used to thread the store object through monadic procedures= . > > 4 and 5 here are observations, but not very useful conclusions. I think > the more interesting question to ask is why are things implemented this > way? > Ideally the closing points would be well made in the previous section, > and this final bit would be a summary. They're supposed to be a short summary of the main lessons the blog post attempts to teach, but I'll consider removing them. > > +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 hopefull= y it will > > +all click eventually! > > Maybe this could be a call to get involved in the community (talk on IRC > or the mailing list? Yeah, good idea :) -- ( --5cc3f916ba10d364804d18b296b0a5302a012e9f7cd33632812b60b82ee4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEE6Vh10NblKE5doNlW7ImHg/nqI20FAmPo9QwACgkQ7ImHg/nq I2026wv+PeZLwwcKTJu38NOTCOQSyw46ZgvZFAOUzD3L/I+i1KE4GEHepxUZBDt1 +IuBvaVKiK5XvwqFwLl3aIbfs0Mf3HGDUKxbhvt4l43/T2EPjpU5eIUG6t69LTSZ jc9sC+jb77rF1sVIOKxe3SNb7+IX642HiVXtHgu8T6o+N2xndZNMyrnQG4pUDnyd dRzwYry2Ke7Hz2cm7wdnnJkG4/ziYOjWliVoniVJhwC7fPjdT0CwqYlvnwNyNjTL B9ItN59aGgOLnraFTVDKD1XJKnBSEyTlIkpi/P4ZK/mX7IBaX4R2MfNQO4/oy8lS r1SkWuDiybx+lE4xv55t+JInCq3GY6F6h6Yq8QkwRsaennSyzxCubRWOHoAeXupj 1Zb1TdQK5Z3asomtMbjsI7clyDDF7jTnPIhN6G0ISH2PCPRs0cdcevrrPX80poPW 6SLeVYRkT3Tns0H50LMXhEApEFwXvUTDfe5M2tkaBQGG1oAVn5Xmxw4osoGt1Osk LYubJIyd =KxYx -----END PGP SIGNATURE----- --5cc3f916ba10d364804d18b296b0a5302a012e9f7cd33632812b60b82ee4--