[GHC] #974: Add unzipEithers, lefts, rights to Data.Either

Conor McBride conor at strictlypositive.org
Fri Feb 15 17:30:01 EST 2008


Hi Russell

On 15 Feb 2008, at 21:36, roconnor at theorem.ca wrote:

> On Fri, 15 Feb 2008, GHC wrote:
>
>> Comment (by igloo):
>>
>> Having reread the thread, I think we are here:
>>
>> We are agreed that we should add
>> {{{
>> lefts  :: [Either a b] -> [a]
>> rights :: [Either a b] -> [b]
>> }}}
>> and that we should add a function with type
>> {{{
>> [Either a b] -> ([a],[b])
>> }}}

Any chance of left-factoring foldMap from the above?

It's funny: what's important about the [] on the
left is that it's Foldable; what's important about
the [] on the right is that it's Alternative. What's
both? More than one candidate, but [] is a runaway
winner perhaps.

Curious stuff.

What if we had

   left   :: Either a b -> Maybe a
   right  :: Either a b -> Maybe b
   may    :: Alternative f => Maybe a -> f a

and suitable other bits and pieces? I fear that

   foldMap ((may . left) &&& (may . right))

is a longer name than you were hoping for, but
it says what it does on the tin.

Cheers

Conor



More information about the Libraries mailing list