Lazy `State` effect
Closed this issue · 5 comments
Is there a reason why the State
effect is strict? I would need one which is lazy, due to keeping in there a data structure which is read from disk and is quite slow to read. It is build with unsafeInterleaveIO
. I am building a filesystem so State
being strict quite hampers the laziness which I need.
Is there a reason why the State effect is strict?
Yes, it's far too easy to introduce a space leak by accidentally using modify
instead of modify'
🙂
I would need one which is lazy
The workaround is quite simple, if you create data Lazy a = Lazy a
and then use State (Lazy a)
instead of State a
, you'll get the desired semantics. How does that sound?
That sounds completely doable :) thanks!
Oh, does it have to be data
? I'd guess so, using newtype
would erase that indirection at runtime.
Yes, has to be data
to create the indirection.
Thanks, I seem to be still having some strictness issues, but I think that's unrelated to no it is noteffectful
, gotta check if Vec
from vector
is lazy