Open
Description
The thing about IO
in multiple languages / libraries is that it is lazy.
Our IO
is not lazy by design. It is done, so Python developers can use it like so: impure(print)(1) # prints "1"
But, we also need to think about other problems as well:
- Retries, with proper lazy
IO
one can retry an operation as many times as one wishes:p = impure_lazy(print)(1); p(); p() # prints "1" twice
- Semantical identity to
Future
, currently it is not similar to regularIO
, becauseFuture
s are lazy: they don't run until they are executed properly - New users will find the similar data-type they already know from other languages / libraries
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
sobolevn commentedon Jul 31, 2020
LazyIO(x)
is basically justIO(lambda: x)
.But, when talking about composition, we need to give it a helping hand:
It is much better than working with
IO(lambda: x)
Lazy
protocol #428IOLikeN
andIOBasedN
#542thepabloaguilar commentedon Sep 4, 2020
This can be useful to create something like
lazy_cond
that accepts lazy objects as the inner values:Today is impossible to make something similar and simple
sobolevn commentedon Jan 27, 2021
Well, I was wrong.
LazyIO
is notIO(lambda: x)
it islambda: IO(x)
efagerberg commentedon Apr 25, 2021
I know the documentation mentions
IO
s are not lazy because it would be more familiar to existing python developers and help with using theimpure
decorator. However I am skeptical that this is as useful in practice. Most people using this library I assume are starting with some traditional understanding of theIO
monad.Taking my personal experience as an example, I learned explicitly that the
IO
monad is supposed to be something like a grenade that the caller pulls the pin from when they are ready, and not just a wrapper to tell the user the data came from some nondeterministic world. This common form of IO in my reading has also been used to build on the ideas of functional composition and equational reasoning.In my example I started in earnest with reading https://github.com/MostlyAdequate/mostly-adequate-guide, maybe my experience is not representative of everyone's. I am just not as sure the value of a simple
IO
container is compared to the traditional definition. The traditional definition helps more to represent a value is non deterministic but still returns a deterministic value, an IO with some function inside of it.