Hi Ludo', 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. Ludovic Courtès writes: > Yes, though it would be nice to have a variant of ‘parameterize’ “that > works for any monad”, that was the intent of ‘mparameterize’. I think what you describe (although I'm not too familiar with Haskell) is like the ReaderT (or StateT if the parameters can change within the monad) monad transformer, where the parameters are stored in the additional state provided by ReaderT. This is however a new monad and different from setting the parameters globally in different functions passed to bind. > 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? 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, that’s because ‘with-fluids*’ is implemented in C, which makes it a > “continuation barrier” (continuations that contain C stack frames cannot > be resumed). It’s a limitation of the current implementation rather > than a bug, strictly speaking. :-) Ah I see, thanks for the explanation! Are there plans to change that and do you think it would be difficult to do? Maybe the suspension could also be done without prompts by instead modifying the store monad, similar to [1]? It would probably be less straightforward though and maybe better suitable for languages like Haskell. Cheers, David [1] https://hackage.haskell.org/package/monad-coroutine-0.9.2/docs/Control-Monad-Coroutine.html