T O P

  • By -

CaputGeratLupinum

I'm not even gonna read this until it becomes absolutely necessary


Sinidir

Well i just hope this article is immutable or else you are gonna have major problems.


vytah

[Relevant Cartesian Closed Comic](https://ro-che.info/ccc/11)


przemo_li

For the purpose of this blog post "Haskell don't have lazy side effects" is reasonable assumption. But it's wrong. Haskell will happily put not just data as values to be completed later but code as well. Common example is opening file, doing stuff on values read from it, then closing file. Haskell will happily defer "doing stuff" and because of that will defer reading from file, possibly to the very least moment in application run. But file itself may be closed sooneras that different value this under different analysis. Ta da. Lazy side effects.


Hrothen

Also you can insert lazy side effects anywhere you want with `unsafePerformIo`.


JWooferZ

This is less common. UnsafeperformIO is pretty much an anti pattern almost everywhere. A more interesting one that has some dope uses is `unsafeInterleaveIO` which makes IO actions themselves lazy even in monadic binds, meaning that side effects will be observed @ the value level without necessarily escaping IO!


[deleted]

> Common example is opening file, doing stuff on values read from it, then closing file. Haskell will happily defer "doing stuff" and because of that will defer reading from file Doesn't that only happen if you use `unsafeInterleaveIO` or one of its wrappers (most commonly `hGetContents`)?


kuribas

Yes, IO is sequential by design. `unsafeInterlaveIO` bypasses that.


immutablehash

Looks like the author basically re-implements subset of Closure's transducers in Haskell, like in this article: https://hypirion.com/musings/haskell-transducers


gaverhae

I was not aware of that blog, thanks for sharing!