Subject: [bug#76485] [PATCH] gexp: ‘with-parameters’ properly handles ‘%graft?’.

From: Ludovic Courtès <[email-masked]>
Date: Mon, 03 Mar 2025 19:03:19 +0100

Hi David,

David Elsing <[email-masked]> skribis:

> I thought about it some more and I think my issue is that in general,
> the number of times a function passed to bind is evaluated is not fixed.
> Attached is an example for a monad which acts as a combination of the
> state monad and the maybe monad. I used two parameters, because they are
> set at different times in the implementation of `mparameterize' (but
> this seems to be a different issue to me). In particular, p2 is not
> restored at the end, because no function application is done for a
> "nothing" value.
>
> Another problematic example would be a "coroutine" monad [1], which can
> pause the evaluation of its "steps", during which the parameters could
> be used or changed elsewhere.

Hmm right.

I guess my contradiction is that I’m looking for a “generic” solution
but whose genericity is limited by the set of monads defined in (guix
monads) and by my imagination.  :-)

>> Because of that, I have a preference for ‘mparameterize’ rather than
>> ‘state-parameterize’ or any other specific variant.
>>
>> WDYT?
>
> To my understanding, what we actually want is to affect the way the
> function of the state monad applies to the passed state, or formulated
> in a different way, the state to include the parameters. This would be
> effectively achieved using `with-fluids*' inside the monadic procedure
> (except that they are not part of the final state). It can be though of
> expanding the state of the state monad with the parameters, where the
> initial state contains the "outside" parameters. Of course, now there
> are two different ways to pass on state, through the state monad and the
> parameters... :)
>
> Does this make sense?

I think so. :-)

The core of the problem here is that (guix monads), to a large extent,
addresses problems already addressed by other Scheme constructs such as
parameters/fluids, but in an incompatible way.  So really,
‘mparameterize’ and the many commits that fixed interactions between
‘%current-system’ & co. and the monad are really band aid.

So in this case I’m also looking for a “quick fix” more than extending
(guix monads).

> Because `with-fluids*' does not work with prompts, I still think your
> solution is a good workaround when specialized for the state monad, as
> long as the parameters are not used externally until the execution is
> completely finished.

Yes, the semantics are clumsy.

Would you like to send a patch that does it the way you want?
Preferably limited to fixing ‘with-parameters’ in particular so it also
works for ‘%graft?’.

Or are you saying that the patch at the beginning of this thread (where
‘mcall-with-parameters’ is specialized for the state monad) is good
enough?

Tell me what you prefer.  :-)

(There’s a couple of patch series depending on this fix.)

Thanks,
Ludo’.