Proposal: Add a few extra members to Foldable and Traversable classes

David Feuer david.feuer at gmail.com
Thu Sep 18 21:49:10 UTC 2014


R.W. Barton was having trouble spitting out the words "length of a set",
and the same holds for all sorts of other things, but unfortunately I think
you're right. Proposal amended: put length in the Foldable class.

On Thu, Sep 18, 2014 at 5:43 PM, Edward Kmett <ekmett at gmail.com> wrote:

> Choosing the name `size` isn't free.
>
> If we chose `length` then the existing code continues to work, code that
> was hiding it on import continues to hide it and you don't get conflicts.
>
> Picking 'size' is compatible with common practice, but means a ton of
> modules would break.
>
> Given the two solutions, one that doesn't break anything and one that
> does, with negligible differences between them otherwise, I'd prefer the
> one that causes the least amount of pain.
>
> -Edward
>
> On Thu, Sep 18, 2014 at 5:37 PM, David Feuer <david.feuer at gmail.com>
> wrote:
>
>> To go along with Herbert Valerio Riedel's moving functions from Foldable
>> and Traversable to Prelude, I realized that `null` and `size` make sense
>> for all Foldables; Reid W. Barton noted that these can have optimized
>> implementations for many containers. He also noted that scanl1 and scanr1
>> make sense for general Traversables. I therefore propose:
>>
>> Add `null` and `size` to the Foldable class. Default implementations:
>>
>> null = foldr (\_ _ -> False) True
>>
>> size = foldl' (\acc _ -> acc+1) 0
>>
>> Add `scanl1` and `scanr1` to the Traversable class. Default
>> implementations are a little less simple.
>>
>> David
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://www.haskell.org/mailman/listinfo/libraries
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140918/6172a8da/attachment.html>


More information about the Libraries mailing list