Proposal: Add missing Foldable/Traversable instances for Prelude types

Edward Kmett ekmett at
Sat Jan 22 05:16:46 CET 2011

I went with the default being to avoid prematurely forcing a bottom when
possible, to avoid being called out by the strictness police, but I'm not
terribly wedded to the behavior.


On Fri, Jan 21, 2011 at 7:27 PM, Isaac Dupree <
ml at> wrote:

> On 01/21/11 18:33, Edward Kmett wrote:
>> I'd like to propose adding the following missing instances to
>> Data.Foldable
>> and Data.Traversable respectively, since there isn't a canonical location
>> that they could be added outside of those packages without orphans, their
>> definition is unambiguous, and they are quite useful (plus, I happen to
>> need
>> them for a monad transformer in my adjunctions package).
>> instance Foldable (Either a) where
>>   foldMap f (Left a) = mempty
>>   foldMap f (Right b) = f b
>> instance Foldable ((,)e) where
>>   foldMap f ea = f (snd ea)
>> instance Traversable (Either a) where
>>   traverse f (Left a) = pure (Left a)
>>   traverse f (Right a) = Right<$>  f a
>> instance Traversable ((,)e) where
>>   traverse f ~(e,a) = (,) e<$>  f a
> Those look correct.  Is there some reason you chose to make the (,)
> instances less strict in the pair?  For example, traverse on "undefined"
> gives you, modulo the applicative layer, "(undefined, f undefined)".  (I
> haven't thought of a reason (practical or theoretical) for either behavior.)
> -Isaac
> _______________________________________________
> Libraries mailing list
> Libraries at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list