* Alternative syntax for interacting with the store monad
@ 2024-11-30 22:50 Justin Veilleux
2024-12-02 17:15 ` Simon Tournier
2024-12-14 23:41 ` Ludovic Courtès
0 siblings, 2 replies; 5+ messages in thread
From: Justin Veilleux @ 2024-11-30 22:50 UTC (permalink / raw)
To: guix-devel
Hello.
I was reading
https://guix.gnu.org/en/blog/2023/dissecting-guix-part-2-the-store-monad/ and
was wondering if using Guile scheme's ~call-with-prompt~ for interacting with the
store monad had been considered. With ~call-with-prompt~, one can recreate an
~async-await~-like syntax in scheme. I think using this syntax (instead of the
~mlet~ macros and ~store-bind~) might be easier to use for beginners as many people
already intuitively know how to use ~async&await~ which is not the case for the
"explicitely monadic" operations.
Here is a snippet of code illustrating how one could use any monad (with
functions ~bind-fn~ and ~pure-fn~) through the more readable ~async&await~ forms.
#+begin_src scheme
(define-syntax-parameter bind
(lambda (s)
(syntax-violation 'bind "bind used outside `with-monad`" s)))
(define-syntax-parameter pure
(lambda (s)
(syntax-violation 'pure "pure used outside `with-monad`" s)))
(define-syntax-rule (with-monad bind-fn pure-fn body body* ...)
(let ((bind-fn bind-fn)
(pure-fn pure-fn)
(prompt-tag (make-prompt-tag)))
(syntax-parameterize
((bind (lambda (s)
(syntax-case s ()
((_ x) #'(abort-to-prompt prompt-tag x)))))
(pure (lambda (s)
(syntax-case s ()
((_ x) #'(pure-fn x))))))
(define (handler kont mval)
(bind-fn
mval
(lambda (x)
(call-with-prompt prompt-tag
(lambda () (kont x))
handler))))
(call-with-prompt prompt-tag
(lambda ()
body body* ...)
handler))))
(define (list-bind xs f)
(apply append! (map f xs)))
(define list-pure list)
(with-monad list-bind list-pure
(let ((x (bind '(1 2))))
(pure
(list
x
(bind '("thing1" "thing2"))))))
;; => ((1 "thing1") (1 "thing2") (2 "thing1") (2 "thing2"))
#+end_src
Maybe the the performance costs associated with using delimited continuations
are too high?
What do you think?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Alternative syntax for interacting with the store monad
2024-11-30 22:50 Alternative syntax for interacting with the store monad Justin Veilleux
@ 2024-12-02 17:15 ` Simon Tournier
2025-01-02 15:04 ` Maxim Cournoyer
2024-12-14 23:41 ` Ludovic Courtès
1 sibling, 1 reply; 5+ messages in thread
From: Simon Tournier @ 2024-12-02 17:15 UTC (permalink / raw)
To: Justin Veilleux, guix-devel
Hi,
On Sat, 30 Nov 2024 at 17:50, Justin Veilleux <terramorpha@cock.li> wrote:
> (define (list-bind xs f)
> (apply append! (map f xs)))
>
> (define list-pure list)
>
> (with-monad list-bind list-pure
> (let ((x (bind '(1 2))))
> (pure
> (list
> x
> (bind '("thing1" "thing2"))))))
In [1], Josselin proposed something à la Haskell:
(mdo %store-monad
(drv <- (gexp-derivation "myderivation" test-gexp))
(output <- (return (derivation->output-path drv)))
(built-derivations (list drv))
(return (format #t "~a~%" output)))
Well, the conclusion seems that « it’s normally not necessary to use the
monadic interface unless you’re getting into internals or writing a new
tool. » Therefore, I do not know if improving the syntax is worth.
Cheers,
simon
1: Re: Viewing derivation output in the store
Josselin Poiret <dev@jpoiret.xyz>
Thu, 21 Apr 2022 09:44:05 +0200
id:87v8v2g9tm.fsf@jpoiret.xyz
https://lists.gnu.org/archive/html/guix-devel/2022-04
https://yhetil.org/guix/87v8v2g9tm.fsf@jpoiret.xyz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Alternative syntax for interacting with the store monad
2024-12-02 17:15 ` Simon Tournier
@ 2025-01-02 15:04 ` Maxim Cournoyer
2025-01-03 13:08 ` Simon Tournier
0 siblings, 1 reply; 5+ messages in thread
From: Maxim Cournoyer @ 2025-01-02 15:04 UTC (permalink / raw)
To: Simon Tournier; +Cc: Justin Veilleux, guix-devel
Hi Simon,
Simon Tournier <zimon.toutoune@gmail.com> writes:
> Hi,
>
> On Sat, 30 Nov 2024 at 17:50, Justin Veilleux <terramorpha@cock.li> wrote:
>
>> (define (list-bind xs f)
>> (apply append! (map f xs)))
>>
>> (define list-pure list)
>>
>> (with-monad list-bind list-pure
>> (let ((x (bind '(1 2))))
>> (pure
>> (list
>> x
>> (bind '("thing1" "thing2"))))))
>
> In [1], Josselin proposed something à la Haskell:
>
> (mdo %store-monad
> (drv <- (gexp-derivation "myderivation" test-gexp))
> (output <- (return (derivation->output-path drv)))
> (built-derivations (list drv))
> (return (format #t "~a~%" output)))
>
> Well, the conclusion seems that « it’s normally not necessary to use the
> monadic interface unless you’re getting into internals or writing a new
> tool. » Therefore, I do not know if improving the syntax is worth.
That's not a super convincing argument to me (I sometimes dabble with
the monad, and the reason I don't do it more often at the REPL is partly
because I need to retrain myself how to use it every time :-)).
Something more intuitive could help, though I agree having multiple
flavors of one interface could lead to poor consistency in the code
base...
I'm divided.
--
Thanks,
Maxim
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Alternative syntax for interacting with the store monad
2025-01-02 15:04 ` Maxim Cournoyer
@ 2025-01-03 13:08 ` Simon Tournier
0 siblings, 0 replies; 5+ messages in thread
From: Simon Tournier @ 2025-01-03 13:08 UTC (permalink / raw)
To: Maxim Cournoyer; +Cc: Justin Veilleux, guix-devel
Hi Maxim,
On Fri, 03 Jan 2025 at 00:04, Maxim Cournoyer <maxim.cournoyer@gmail.com> wrote:
> (I sometimes dabble with
> the monad, and the reason I don't do it more often at the REPL is partly
> because I need to retrain myself how to use it every time :-)).
> Something more intuitive could help
Well, if we are speaking about REPL, I think one direction to explore
seems about meta command. Time to time, I use run-in-store or
enter-store-monad and for my use cases, they have been enough.
Could you provide an example of what you would like to run from the
REPL?
Cheers,
simon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Alternative syntax for interacting with the store monad
2024-11-30 22:50 Alternative syntax for interacting with the store monad Justin Veilleux
2024-12-02 17:15 ` Simon Tournier
@ 2024-12-14 23:41 ` Ludovic Courtès
1 sibling, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2024-12-14 23:41 UTC (permalink / raw)
To: Justin Veilleux; +Cc: guix-devel
Hello,
Justin Veilleux <terramorpha@cock.li> skribis:
> Maybe the the performance costs associated with using delimited continuations
> are too high?
Yes, I think it would be too high. Currently it’s designed so that
common operations can be inlined:
https://lists.gnu.org/archive/html/guix-devel/2017-05/msg00041.html
Ludo’.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-03 18:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-30 22:50 Alternative syntax for interacting with the store monad Justin Veilleux
2024-12-02 17:15 ` Simon Tournier
2025-01-02 15:04 ` Maxim Cournoyer
2025-01-03 13:08 ` Simon Tournier
2024-12-14 23:41 ` Ludovic Courtès
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.