3 ms·
> I don't think it really makes sense to call the way side effects happen in Haskell "lazy". I didn't actually say this. I was suggesting a lazy chain of IO ac
by willtim 9y ago
> I don't think it really makes sense to call the way side effects happen in Haskell "lazy".
I didn't actually say this. I was suggesting a lazy chain of IO actions for such problems. For example, ListT a IO, instead of a regular lazy list with hidden side-effects. The Haskell types help make the distinction clear.
> Instead, your program returns a pure structure which describes how side effects should be executed
Yes exactly, the pure structure can still be computed lazily on demand, providing IO actions.
My favourite Hackage streaming library for Haskell is "streaming" and it can work exactly this way.
- Tarean 9y agoWorth noting that ListTs bind isn't associative for most base monads including IO and it is deprecated for a reason. Also, by it's nature ListT can't stream IO unless you use lazy IO aka lazyRead aka unsafeInterleaveIO which deserves its name.
- willtim 9y agoI am assuming "ListT done right" not the deprecated one (which is not even a chain of actions). Here is a definition, to be completely clear: newtype ListT m a = ListT (m (Maybe (a, ListT m a))) It is a nice simple example of an effectful streaming type. > Also, by it's nature ListT can't stream IO This is only true of the deprecated one, which is also misnamed. The community is rightly re-using the name for the behaviour shown above. See list-t on hackage, or the implementation that comes with Pipes.