* Struggling to write Dissecting Guix, Part 2
@ 2023-01-25 7:12 (
2023-01-25 9:58 ` zimoun
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: ( @ 2023-01-25 7:12 UTC (permalink / raw)
To: guix-devel
[-- Attachment #1: Type: text/plain, Size: 647 bytes --]
Hello Guix,
I've been struggling to write Part 2 of Dissecting Guix; I'm just not sure where to start to
explain monads.
It's hard for a variety of reasons, those being that:
- Guile has no type system, so you can't express monads in terms of types
- Guix doesn't implement very many monads (only state, identity, and store), so it's
difficult to explain with a simpler monad, as there are no simpler monads
- Guix doesn't have functors or monoids either, so it's hard to "progressively" explain
first functors, then monoids, then monads
- Monads are just difficult in general :P
Any suggestions? :/
-- (
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-25 7:12 Struggling to write Dissecting Guix, Part 2 (
@ 2023-01-25 9:58 ` zimoun
2023-01-26 6:32 ` (
2023-01-25 15:54 ` Wojtek Kosior via Development of GNU Guix and the GNU System distribution.
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: zimoun @ 2023-01-25 9:58 UTC (permalink / raw)
To: (, guix-devel
Hi,
On Wed, 25 Jan 2023 at 07:12, "(" <paren@disroot.org> wrote:
> I've been struggling to write Part 2 of Dissecting Guix; I'm just not sure where to start to
> explain monads.
Here my attempt to explain monads using Guile:
1: https://simon.tournier.info/posts/2021-02-03-monad.html
My aim was to provide the “intuition” of the concept. Therefore, I have
tried to explain the monad concept using as simple as possible other
concepts and in the same time I tried to avoid the “monad fallacy” [2].
(summarized by «Monads are Like Burritos» ;-)))
> It's hard for a variety of reasons, those being that:
>
> - Guile has no type system, so you can't express monads in terms of types
I do not think the concept of monad is related to the type system but
instead it appears to me related to the composition.
> - Guix doesn't implement very many monads (only state, identity, and store), so it's
> difficult to explain with a simpler monad, as there are no simpler monads
In [1], I am using the simple monads: list and maybe.
Their implementation is poor but they bring the concept to the table.
Well, I planned to use this introduction of the concepts to then write
another post about the state monad – which is the only we are really
interested in. ;-)
> - Guix doesn't have functors or monoids either, so it's hard to "progressively" explain
> first functors, then monoids, then monads
I think monad can be introduced using the well-known ’map’ which uses
functor without digging in too much details.
> - Monads are just difficult in general :P
Well, from my point of view, it is hard because the concept appears
difficult at first then after the oohh moment it becomes hard to explain
without using the concept itself. IMHO, it is well summarized in this
post:
2: https://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/
Cheers,
simon
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-25 7:12 Struggling to write Dissecting Guix, Part 2 (
2023-01-25 9:58 ` zimoun
@ 2023-01-25 15:54 ` Wojtek Kosior via Development of GNU Guix and the GNU System distribution.
2023-01-26 6:33 ` (
2023-01-26 11:17 ` Simon Tournier
2023-01-25 19:39 ` david larsson
2023-01-26 20:45 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
3 siblings, 2 replies; 12+ messages in thread
From: Wojtek Kosior via Development of GNU Guix and the GNU System distribution. @ 2023-01-25 15:54 UTC (permalink / raw)
To: (; +Cc: guix-devel
[-- Attachment #1: Type: text/plain, Size: 1919 bytes --]
Hi, Paren!
> - Guile has no type system, so you can't express monads in terms of types
While Guile is dynamically typed, functions we define in it generally
do expect their arguments to be of certain types. And they also
generally guarantee their return values to be of certain types. So even
though there's no static type checking, it is still possible (and often
practical) to treat the functions as being typed.
Btw, I really like the explanation of a monad as function taking World
as one of its arguments and producing a modified World. Although you
probably already have your own favorite sources on the topic, here[1] is
the paper (written by someone at Microsoft, lol) where I found this
approach.
Happy dissecting,
Wojtek
[1] https://www.cs.tufts.edu/comp/150PLD/Papers/awkward.pdf
-- (sig_start)
website: https://koszko.org/koszko.html
PGP: https://koszko.org/key.gpg
fingerprint: E972 7060 E3C5 637C 8A4F 4B42 4BC5 221C 5A79 FD1A
♥ R29kIGlzIHRoZXJlIGFuZCBsb3ZlcyBtZQ== | ÷ c2luIHNlcGFyYXRlZCBtZSBmcm9tIEhpbQ==
✝ YnV0IEplc3VzIGRpZWQgdG8gc2F2ZSBtZQ== | ? U2hhbGwgSSBiZWNvbWUgSGlzIGZyaWVuZD8=
-- (sig_end)
On Wed, 25 Jan 2023 07:12:45 +0000
"(" <paren@disroot.org> wrote:
> Hello Guix,
>
> I've been struggling to write Part 2 of Dissecting Guix; I'm just not sure where to start to
> explain monads.
>
> It's hard for a variety of reasons, those being that:
>
> - Guile has no type system, so you can't express monads in terms of types
> - Guix doesn't implement very many monads (only state, identity, and store), so it's
> difficult to explain with a simpler monad, as there are no simpler monads
> - Guix doesn't have functors or monoids either, so it's hard to "progressively" explain
> first functors, then monoids, then monads
> - Monads are just difficult in general :P
>
> Any suggestions? :/
>
> -- (
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-25 7:12 Struggling to write Dissecting Guix, Part 2 (
2023-01-25 9:58 ` zimoun
2023-01-25 15:54 ` Wojtek Kosior via Development of GNU Guix and the GNU System distribution.
@ 2023-01-25 19:39 ` david larsson
2023-01-26 6:34 ` (
2023-01-26 20:45 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
3 siblings, 1 reply; 12+ messages in thread
From: david larsson @ 2023-01-25 19:39 UTC (permalink / raw)
To: (; +Cc: guix-devel, guix-devel-bounces+david.larsson=selfhosted.xyz
On 2023-01-25 08:12, ( wrote:
> Hello Guix,
>
> I've been struggling to write Part 2 of Dissecting Guix; I'm just not
> sure where to start to
> explain monads.
>
> It's hard for a variety of reasons, those being that:
>
> - Guile has no type system, so you can't express monads in terms of
> types
> - Guix doesn't implement very many monads (only state, identity, and
> store), so it's
> difficult to explain with a simpler monad, as there are no simpler
> monads
> - Guix doesn't have functors or monoids either, so it's hard to
> "progressively" explain
> first functors, then monoids, then monads
> - Monads are just difficult in general :P
>
> Any suggestions? :/
>
> -- (
Hi,
Im not an expert on monads by any means, but...
There's a monad tutorial fallacy to avoid:
https://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/
written by someone Brent: "Associate Professor of Computer Science at
Hendrix College. Functional programmer, mathematician, teacher, pianist,
follower of Jesus."
And, personally, I liked this tutorial:
https://towardsdatascience.com/monads-from-the-lens-of-imperative-programmer-af1ab8c8790c
Maybe it helps, maybe not.
Best regards,
David
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-25 9:58 ` zimoun
@ 2023-01-26 6:32 ` (
0 siblings, 0 replies; 12+ messages in thread
From: ( @ 2023-01-26 6:32 UTC (permalink / raw)
To: zimoun, guix-devel
[-- Attachment #1: Type: text/plain, Size: 174 bytes --]
Hey Simon,
On Wed Jan 25, 2023 at 9:58 AM GMT, zimoun wrote:
> 1: https://simon.tournier.info/posts/2021-02-03-monad.html
Thanks! This looks helpful.
-- (
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-25 15:54 ` Wojtek Kosior via Development of GNU Guix and the GNU System distribution.
@ 2023-01-26 6:33 ` (
2023-01-26 11:17 ` Simon Tournier
1 sibling, 0 replies; 12+ messages in thread
From: ( @ 2023-01-26 6:33 UTC (permalink / raw)
To: Wojtek Kosior; +Cc: guix-devel
[-- Attachment #1: Type: text/plain, Size: 441 bytes --]
On Wed Jan 25, 2023 at 3:54 PM GMT, Wojtek Kosior wrote:
> While Guile is dynamically typed, functions we define in it generally
> do expect their arguments to be of certain types. And they also
> generally guarantee their return values to be of certain types. So even
> though there's no static type checking, it is still possible (and often
> practical) to treat the functions as being typed.
I suppose that's true :)
-- (
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-25 19:39 ` david larsson
@ 2023-01-26 6:34 ` (
2023-01-28 18:28 ` david larsson
0 siblings, 1 reply; 12+ messages in thread
From: ( @ 2023-01-26 6:34 UTC (permalink / raw)
To: david larsson; +Cc: guix-devel, guix-devel-bounces+david.larsson=selfhosted.xyz
[-- Attachment #1: Type: text/plain, Size: 211 bytes --]
On Wed Jan 25, 2023 at 7:39 PM GMT, david larsson wrote:
> https://towardsdatascience.com/monads-from-the-lens-of-imperative-programmer-af1ab8c8790c
I'm not too sure about this one, I'm afraid.
-- (
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-25 15:54 ` Wojtek Kosior via Development of GNU Guix and the GNU System distribution.
2023-01-26 6:33 ` (
@ 2023-01-26 11:17 ` Simon Tournier
2023-01-26 20:03 ` bokr
1 sibling, 1 reply; 12+ messages in thread
From: Simon Tournier @ 2023-01-26 11:17 UTC (permalink / raw)
To: Wojtek Kosior, (; +Cc: guix-devel
Hi,
On Wed, 25 Jan 2023 at 16:54, Wojtek Kosior via "Development of GNU Guix and the GNU System distribution." <guix-devel@gnu.org> wrote:
> here[1] is
> the paper (written by someone at Microsoft, lol) where I found this
> approach.
> [1] https://www.cs.tufts.edu/comp/150PLD/Papers/awkward.pdf
The author of [1] is Simon Peyton Jones [2]. One of the designers of
the Haskell programming language and one of the main implementer of the
Haskell compiler GHC. And a great speaker and author. :-)
2: <https://en.wikipedia.org/wiki/Simon_Peyton_Jones>
Cheers,
simon
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-26 11:17 ` Simon Tournier
@ 2023-01-26 20:03 ` bokr
2023-01-27 11:50 ` Simon Tournier
0 siblings, 1 reply; 12+ messages in thread
From: bokr @ 2023-01-26 20:03 UTC (permalink / raw)
To: Simon Tournier; +Cc: Wojtek Kosior, (, guix-devel
Hi Simon,
On +2023-01-26 12:17:27 +0100, Simon Tournier wrote:
> Hi,
>
> On Wed, 25 Jan 2023 at 16:54, Wojtek Kosior via "Development of GNU Guix and the GNU System distribution." <guix-devel@gnu.org> wrote:
>
> > here[1] is
> > the paper (written by someone at Microsoft, lol) where I found this
> > approach.
>
> > [1] https://www.cs.tufts.edu/comp/150PLD/Papers/awkward.pdf
>
> The author of [1] is Simon Peyton Jones [2]. One of the designers of
> the Haskell programming language and one of the main implementer of the
> Haskell compiler GHC. And a great speaker and author. :-)
>
> 2: <https://en.wikipedia.org/wiki/Simon_Peyton_Jones>
>
> Cheers,
> simon
>
Indeed, Simon Peyton Jones is tops.
You may be interested in this[3], if you have not seen it:
3: <https://simon.peytonjones.org/assets/pdfs/verse-conf.pdf>
From the introduction:
--8<---------------cut here---------------start------------->8---
Functional logic languages have a rich literature, but it is
tricky to give them a satisfying semantics. In this paper we
describe the Verse calculus, VC, a new core calculus for
functional logical programming. Our main contribution is to
equip VC with a small-step rewrite semantics, so that we can
reason about a VC program in the same way as one does with
lambda calculus; that is, by applying successive rewrites to
it.
This draft paper describes our current thinking about Verse.
It is very much a work in progress, not a finished product.
The broad outlines of the design are stable. However, the
details of the rewrite rules may well change; we think that
the current rules are not confluent, in tiresome ways. (If
you are knowledgeable about confluence proofs, please talk
to us!) We are eager to enagage in a dialogue with the
community. Please do write to us.
--8<---------------cut here---------------end--------------->8---
Some ideas to enrich guix or the guile language pagoda?
It is interesting that Epic Games has apparently funded quite a
collection of heavies to do some deep abstract thinking.
I imagine SPJ is enjoying discussions. Check the author list!
I got the link at [4] which is much snappier serving than it was
before. (It's a place to go if you are in the mood for something chewy ;)
It also has interesting programming language historical genealogy diagrams.
4: <http://lambda-the-ultimate.org/>
(I hope they get https going ;-)
--
Regards,
Bengt Richter
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-25 7:12 Struggling to write Dissecting Guix, Part 2 (
` (2 preceding siblings ...)
2023-01-25 19:39 ` david larsson
@ 2023-01-26 20:45 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
3 siblings, 0 replies; 12+ messages in thread
From: Felix Lechner via Development of GNU Guix and the GNU System distribution. @ 2023-01-26 20:45 UTC (permalink / raw)
To: (; +Cc: guix-devel
Hi,
On Tue, Jan 24, 2023 at 11:13 PM ( <paren@disroot.org> wrote:
>
> I've been struggling to write Part 2 of Dissecting Guix
If it's a matter of explanatory power, I might suggest switching to an
integrative approach and perspective for part 2—i.e. "Putting the
parts of Guix back together". After all, the motivation behind monads
is to combine purely functional components into a larger, effectful,
and more useful sequence of completed tasks.
Kind regards
Felix
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-26 20:03 ` bokr
@ 2023-01-27 11:50 ` Simon Tournier
0 siblings, 0 replies; 12+ messages in thread
From: Simon Tournier @ 2023-01-27 11:50 UTC (permalink / raw)
To: bokr; +Cc: Wojtek Kosior, (, guix-devel
Hi,
On jeu., 26 janv. 2023 at 21:03, bokr@bokr.com wrote:
> Indeed, Simon Peyton Jones is tops.
If I might, I would recommend « Build Systems à la Carte » [1]. It
provides a framework to deal with various build system; Guix being one,
see Table 2.
1: https://www.microsoft.com/en-us/research/uploads/prod/2018/03/build-systems.pdf
> 4: <http://lambda-the-ultimate.org/>
Oh cool! Thanks.
Cheers,
simon
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Struggling to write Dissecting Guix, Part 2
2023-01-26 6:34 ` (
@ 2023-01-28 18:28 ` david larsson
0 siblings, 0 replies; 12+ messages in thread
From: david larsson @ 2023-01-28 18:28 UTC (permalink / raw)
To: (; +Cc: guix-devel, guix-devel-bounces+david.larsson=selfhosted.xyz
[-- Attachment #1: Type: text/plain, Size: 855 bytes --]
On 2023-01-26 07:34, ( wrote:
> On Wed Jan 25, 2023 at 7:39 PM GMT, david larsson wrote:
>> https://towardsdatascience.com/monads-from-the-lens-of-imperative-programmer-af1ab8c8790c
>
> I'm not too sure about this one, I'm afraid.
>
> -- (
What are you not too sure about?
There is also pseudo-code (so not python) version of it on Wikipedia
that's almost identical:
https://en.wikipedia.org/wiki/Monad_(functional_programming)#Program_logging
I thought the wikipedia version is kind of clearer mainly because it's a
little more "complete"-feeling. I added some stuff myself to the first
article making it more like the wikipedia, etc, the and attached it here
if anyone's interested. That's still in python, but if I ever were to
write a monad in guile, I'd almost certainly start with trying to
translate this one.
Best regards,
David
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mathlogsmonad-mini.py --]
[-- Type: text/x-python; name=mathlogsmonad-mini.py, Size: 1941 bytes --]
from typing import Tuple
def square(num: int) -> int:
return num * num
def double(num: int) -> int:
return num + num
def square_with_print_return(num: int) -> Tuple[int, str]:
logs = "Currrent num " + str(num) + ". "
return (square(num), logs)
def double_with_print_return(num: int) -> Tuple[int, str]:
logs = "Currrent num " + str(num) + ". "
return (double(num), logs)
def bind(func, tuple: Tuple[int, str]) -> Tuple[int, str]:
res = func(tuple[0])
return (res[0], tuple[1] + res[1])
def unit(number: int) -> Tuple[int, str]:
return (number, "")
# Now you can do this, more or less nested:
#print(bind(square_with_print_return, unit(5)))
#print(bind(square_with_print_return, (bind(square_with_print_return, bind(square_with_print_return,bind(square_with_print_return,unit(5)))))))
# it's nicer with infix. This class is a hack.
class Infix:
def __init__(self, function):
self.function = function
def __ror__(self, other):
return Infix(lambda x, self=self, other=other: self.function(other, x))
def __or__(self, other):
return self.function(other)
def __rlshift__(self, other):
return Infix(lambda x, self=self, other=other: self.function(other, x))
def __rshift__(self, other):
return self.function(other)
def __call__(self, value1, value2):
return self.function(value1, value2)
x=Infix(lambda f,x: bind(f,x))
print( square_with_print_return |x| (double_with_print_return |x| unit(4) ) )
# And some extra functional stuff
def curry(f,x):
def curried_function(*args, **kw):
return f(*((x,)+args),**kw)
return curried_function
curry=Infix(curry)
import operator
add5 = operator.add |curry| 5
print(add5(6))
def add5_with_print_return(num: int) -> Tuple[int,str]:
logs = "Current num is " + str(num) + ". "
return (5+num,logs)
print( add5_with_print_return |x| (double_with_print_return |x| unit(4) ) )
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2023-01-28 18:28 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-25 7:12 Struggling to write Dissecting Guix, Part 2 (
2023-01-25 9:58 ` zimoun
2023-01-26 6:32 ` (
2023-01-25 15:54 ` Wojtek Kosior via Development of GNU Guix and the GNU System distribution.
2023-01-26 6:33 ` (
2023-01-26 11:17 ` Simon Tournier
2023-01-26 20:03 ` bokr
2023-01-27 11:50 ` Simon Tournier
2023-01-25 19:39 ` david larsson
2023-01-26 6:34 ` (
2023-01-28 18:28 ` david larsson
2023-01-26 20:45 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
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.