Deprecate Foldable for Either

Dan Burton danburton.email at gmail.com
Thu Mar 2 18:49:40 UTC 2017


Of course errors are swallowed. Look at the type signature.

concat :: Foldable t => t [b] -> [b]
-- t = Either a
concat :: Either a [b] -> [b]

The error type "a" does not appear anywhere in the function's output type.
In the event of an error, the only thing it could possibly produce as
output is an empty list.

I don't think this means that Either's foldable instance is harmful and
should be removed. It's a perfectly good instance that behaves in the
"obvious" Maybe-like way. I do think this is an argument in favor of using
a custom Prelude (which uses functions specialized to lists) when teaching
new students.

Any Traversable instance should absolutely be Foldable, with foldMap =
foldMapDefault, or an optimized version that produces the same result.
Putting `foldMap = error ...` for any Traversable is out of the question,
imo.

-- Dan Burton

On Thu, Mar 2, 2017 at 10:12 AM, Kris Nuttycombe <kris.nuttycombe at gmail.com>
wrote:

> As with all of these discussions, the point of having Either be Foldable
> is not that you're going to call foldMap on an Either value directly.
> Instead, it is that you be able to pass whatever sort of foldable thing you
> choose (which Either certainly is) to a function that only requires
> foldability of its input. By removing or damaging the Foldable instance for
> Either, you don't simply prevent people from encountering problems that
> will be resolved the first time they test their software - you make a whole
> universe of nicely polymorphic functions unavailable for them to use
> without additional effort.
>
> In particular, the idea that one should make all such functions partial by
> throwing an error is repugnant.
>
> Kris
>
> On Thu, Mar 2, 2017 at 10:35 AM, Francesco Ariis <fa-ml at ariis.it> wrote:
>
>> On Thu, Mar 02, 2017 at 05:19:26PM +0000, Oliver Charles wrote:
>> > Personally, I think it would be a shame to lose foldMap on EIther. I
>> > frequently foldMap over Maybe values (where mempty is suitable in case
>> of
>> > "failure"), and I can certainly see myself doing the same thing with
>> Either.
>>
>> I am not trying to be polemic, just to see where the community
>> stands: regarding Either/Maybe: do you have use cases for length
>> (sum) too?
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20170302/1506ba46/attachment.html>


More information about the Libraries mailing list