asum really needs to go into the Foldable class (or something)

David Feuer david.feuer at gmail.com
Wed Nov 5 19:56:49 UTC 2014


No, this doesn't get the job done either. Here are some situations:

1. The Foldable is a cons list, snoc list, or tree
2. The Monoid is right-handed (list-like, IO-like), left-handed
(snoc-list-like), balanced (a balanced tree), or indifferent (Int, Double,
etc).
3. The Monoid is left-strict (certain lazy Nats), right-strict (certain
other ones), entirely strict (Int, etc.), or entirely lazy (an unbalanced
leaf tree).

How can we hope to do something sane in all these cases?
On Nov 5, 2014 2:07 PM, "David Feuer" <david.feuer at gmail.com> wrote:

> Well, I guess I can try to answer my own question. The main distinction is
> between left-handed and right-handed monoids. So the thing to do is to add
> explicitly left-handed and explicitly right-handed versions of these
> functions to Data.Foldable.
> On Nov 5, 2014 2:03 PM, "David Feuer" <david.feuer at gmail.com> wrote:
>
>> OK, so can you suggest a good implementation of sum or asum or traverse_
>> that will work sanely regardless of the monoid? Because I can't think of
>> any way to do that. Or can you think of a better way than FoldableMP to
>> accomplish that objective?
>> On Nov 5, 2014 1:45 PM, "Edward Kmett" <ekmett at gmail.com> wrote:
>>
>>> Please consider me strongly against such a FoldableMP class.
>>>
>>> -Edward
>>>
>>> On Wed, Nov 5, 2014 at 11:42 AM, David Feuer <david.feuer at gmail.com>
>>> wrote:
>>>
>>>> The current definition is "biased", using foldr and <|> instead of
>>>> foldMap and the new Alt. This is a bit awkward in the post-BBP world, but
>>>> we also don't want to just debias it across the board, because if the
>>>> Foldable is holding lists, the debiased version will be very bad.
>>>>
>>>> More generally, there are a number of Foldable members that are very
>>>> awkward, pleading for MPTC, because the sane implementations depend on both
>>>> the container type and the element type. I know we're pushing right up
>>>> against the deadline for 7.10.1, but the current situation is making me
>>>> very nervous.
>>>>
>>>> David
>>>>
>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20141105/cde9499f/attachment.html>


More information about the Libraries mailing list