Proposal: merge Data.Functor.Coproduct into transformers

Sean Leather leather at
Tue Dec 11 11:10:10 CET 2012

On Tue, Dec 11, 2012 at 5:54 AM, Mario Blazevic wrote:

> At the instigation of Edward Kmett, I hereby propose to merge
> Data.Functor.Coproduct module from comonad-transformers into
> transformers.

I've been wishing this datatype was there.

An alternative naming for the module (and the type) would be
> Data.Functor.Sum.

I prefer Sum.

I have a much stronger preference for a new datatype rather than a wrapper
around Either. The wrapping/unwrapping doesn't seem to add anything but
more work when you use it (in pattern matching).

Currently, you have:

> newtype Coproduct f g a = Coproduct { getCoproduct :: Either (f a) (g a) }

Why not this?

> data Sum f g a = SumLeft (f a) | SumRight (g a)

(I'm not particular about the constructor names, though these do seem to
fit the explicit naming style of the transformer functors.) Then, we don't
need the functions left and right, and coproduct becomes:

> unSum :: (f a -> b) -> (g a -> b) -> Sum f g a -> b
> unSum f _ (SumLeft x) = f x
> unSum _ g (SumRight x) = f x

(Also not particular about the name unSum. Could be runSum or getSum, I

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list