[Haskell-cafe] strictness properties of monoidal folds
fischer at nii.ac.jp
Mon Aug 15 05:01:42 CEST 2011
sorry for my slow response.
On Thu, Aug 4, 2011 at 7:10 AM, Alexey Khudyakov
<alexey.skladnoy at gmail.com>wrote:
> On 02.08.2011 08:16, Sebastian Fischer wrote:
>> Data.Foldable also provides the monoidal fold function foldMap. It is
>> left unspecified whether the elements are accumulated leftwards,
>> rightwards or in some other way, which is possible because the combining
>> function is required to be associative. Does this additional freedom for
>> implementors go so far as to allow for strict accumulation?
>> Left and right folds behave identically for finite structures but they
> are different for infinite ones.
I agree that for types like normal lists that allow infinite structure it
makes sense to have different folds like foldr and foldl that are explicit
about the nesting of the combining function.
I don't think that there are laws for foldMap that require it to work for
infinite lists. One could even argue that the monoid laws imply that the
results for folding leftwards and rightwards should be equal, that is
For types that only allow finite sequences (like Data.Sequence or
Data.Vector) this is not an issue. But you convinced me that a strict and
lazy foldMap can be distinguished even for list types that have a strict
append function by using a lazy mappend function for accumulation.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe