Proposal: Add missing Foldable/Traversable instances for Prelude types
Brent Yorgey
byorgey at seas.upenn.edu
Sat Jan 22 17:35:16 CET 2011
On Fri, Jan 21, 2011 at 06:33:10PM -0500, 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
+1
-Brent
More information about the Libraries
mailing list