
23 Dec
2020
23 Dec
'20
4:58 a.m.
On Wed, Dec 23, 2020 at 01:32:38AM -0500, Viktor Dukhovni wrote:
Is there a compelling reason for:
sum = getSum #. foldMap' Sum product = getProduct #. foldMap' Product
rather than:
sum = foldl' (+) 0 product = foldl' (*) 1 [...] The `foldl'` variant looks substantially more efficient (at least for lists), is there some important context in which `foldMap'` is preferable?
Have you benchmarked with optimisations on? I would not be surprised if a small amount of inlining brings them to the same speed. Tom