6 ms·
Hi Author here > Perhaps it is true that worries about space leaks or surprising performance are overblown. But I think that any apology for lazy evaluation in
by slacknatcher12 3y ago
Hi Author here
> Perhaps it is true that worries about space leaks or surprising performance are overblown. But I think that any apology for lazy evaluation in Haskell should attempt to understand and argue against the reasons that someone like SPJ would say ‘the next Haskell will be strict’. (I’m not totally sure what the reason is; maybe it’s just that lazy evaluation is unpopular)
You are completely right. The type (b) of space leaks that are a correctness concern must be addressed. I was intending to do a second post about it.
I have a classification of space leaks that gives rise to defensive patterns to avoid the class (b). In general space leaks come in two varieties:
- Strictness space leaks: there is thunk that to be evaluated need to enter another thunk and another and another, usually growing in size. If we had evaluated in the reduction we could have collapsed the layers accordingly. The classic "foldl' vs foldl" leak is of this kind.
- Liveness space leaks: There is a reference that is kept alive because is needed to evaluate a thunk. If we force the thunk, that reference is marked dead and collected.
Type 1 of leaks are a property of functions with recursive calls or functions are that are binding expressions (such as >>=). They are local property leak. Type 2 are a global property and the more common kind. Obviously seq appropriately on a strict monad solves the issue. I will do another blogpost discussing the defensive patterns.