Zulip Chat Archive
Stream: lean4
Topic: Applicative and do-notation
Shreyas Srinivas (Oct 06 2025 at 18:06):
People have thought about this btw
https://simonmar.github.io/bib/papers/applicativedo.pdf
Shreyas Srinivas (Oct 06 2025 at 18:11):
They make the case they in many cases one can infer when to use applicative combinators instead of monadic bind within do notation
Kyle Miller (Oct 06 2025 at 18:44):
@Shreyas Srinivas That's for Applicative, not Alternative — I don't see anything in the paper that would be relevant. The paper's certainly interesting.
Shreyas Srinivas (Oct 06 2025 at 19:00):
Yeah but alternatives are applicatives
Shreyas Srinivas (Oct 06 2025 at 19:02):
I checked and this is also mentioned in the lean reference manual
The Alternative type class describes applicative functors that additionally have some notion of failure and recovery.
Source: https://lean-lang.org/doc/reference/latest/Functors___-Monads-and--do--Notation/
Eric Wieser (Oct 07 2025 at 11:05):
Shreyas Srinivas said:
They make the case they in many cases one can infer when to use applicative combinators instead of monadic bind within do notation
at risk of derailing the thread further, lean4#10231 and lean4#10202 go a little in this direction
Eric Wieser (Oct 07 2025 at 11:08):
From the paper that you link
But, tantalisingly, fx manifestly isn’t used by the second call, so we actually could run the two in parallel.
Does Lean today have any monads that allow f <$> gx <*> gy to run gx and gy in parallel?
Shreyas Srinivas (Oct 07 2025 at 12:02):
I don't think it is quite off-topic. The same idea that 's applied to applicatives can be applied to alternatives.
Shreyas Srinivas (Oct 07 2025 at 12:05):
Eric Wieser said:
From the paper that you link
But, tantalisingly, fx manifestly isn’t used by the second call, so we actually could run the two in parallel.
Does Lean today have any monads that allow
f <$> gx <*> gyto rungxandgyin parallel?
Monads have a sequential dependency. You always evaluate the first argument to the bind to be able to apply it to the second. So it might not make sense to do this for Monads themselves. However, for applicatives this is not the case, all arguments can be evaluated in parallel (or any sequential order). This is also true for Alternatives, for example multiple match attempts by Parser can be executed in parallel.
Eric Wieser (Oct 07 2025 at 13:05):
Right, hence my question "Does Lean today have any monads that [execute applicative operations] in parallel". I was not asking about bind operations.
Shreyas Srinivas (Oct 07 2025 at 19:44):
Eric Wieser said:
Right, hence my question "Does Lean today have any monads that [execute applicative operations] in parallel". I was not asking about bind operations.
It wouldn’t be a monad without the bind operation would it? Just an applicative? Anyway, I think we are in broad agreement that a do notation for applicatives (and by extension alternatives) with parallel execution is worth exploring.
Eric Wieser (Oct 07 2025 at 19:46):
Irrespective of whether the bind operation exists, my question is about f <$> gx <*> gy which does not mention it. Of course, a monad can implement seq and map in terms of bind, but it is not required to do so.
Shreyas Srinivas (Oct 07 2025 at 20:21):
To further clarify, there are two separate, somewhat orthogonal issues :
- Extending
donotation to desugar into the applicative<*>(and maybe also<|>) operator instead of the monadic>>=operator where possible. - Parallel execution of applicative actions.
Notification Bot (Oct 07 2025 at 20:58):
13 messages were moved here from #lean4 > Alternative and do-notation by Eric Wieser.
Eric Wieser (Oct 07 2025 at 20:59):
(I think this discussion is worth keeping, but let's remove the distraction from the first | proposal; feel free to edit the first message to quote something from the original thread to make it make more sense)
Last updated: Dec 20 2025 at 21:32 UTC