foldl' semantic change

wren romano winterkoninkje at gmail.com
Fri Jun 10 22:50:19 UTC 2016


On Fri, Jun 10, 2016 at 1:40 PM, Bart Massey <bart.massey at gmail.com> wrote:
> It's hard for me to imagine relying on getting bottom instead of a result.

Thanks to the presence of extensible exceptions, some people may do
things like (foldl' f (throw blah)) and then catch the exception
further up. It's terrible, I know. Using explicit continuations would
be much cleaner. But still, it is what it is


> However, it's also
> hard for me to imagine relying on foldl' forcing the initial value in the
> case of folding on an empty list, and in non-empty list cases the folding
> function is likely going to be strict on the accumulator anyhow.

The main issue I see here is a sort of inference issue. That is, if
the initial value to fold' is marked as lazy then we might build up
some huge thunk which must in practice actually get forced; whereas if
the initial value is strict then we can percolate the knowledge of
that strictness further up, potentially evaluating things more eagerly
and thus avoiding the overhead of thunking, allocation, etc.

-- 
Live well,
~wren


More information about the Libraries mailing list