Proposal: Add isLeft/isRight to Data.Either

Simon Marlow marlowsd at gmail.com
Mon Dec 10 16:55:57 CET 2012


On 05/12/12 17:33, Bryan O'Sullivan wrote:
> On Wed, Dec 5, 2012 at 8:16 AM, Henning Thielemann
> <lemming at henning-thielemann.de <mailto:lemming at henning-thielemann.de>>
> wrote:
>
>     The same can be asked for
>
>     Prelude> :t either (const False) (const True)
>     either (const False) (const True) :: Either a b -> Bool
>
>     or
>
>     isLeft = isJust . maybeLeft
>
>
> We at least have evidence that isLeft and isRight are actually present
> in several packages. That helps this proposal squeak over my bar, so I'm
> +0 on it.
>
> I think that maybeLeft and maybeRight are interesting, but the burden of
> proof for "these things solve a problem that actually exists" is a
> little higher. Consider me -0.01.

I needed maybeRight just the other day, as a matter of fact.

timeout n m
     | n <  0    = fmap Just m
     | n == 0    = return Nothing
     | otherwise = do
         r <- race (threadDelay n) m
         case r of
           Left _  -> return Nothing
           Right a -> return (Just a)

would have been

timeout n m
     | n <  0    = fmap Just m
     | n == 0    = return Nothing
     | otherwise = fmap maybeRight $ race (threadDelay n) m

(I'd rather not use `either`, it's one of those functions whose type I 
always have to look up)

> In general, I feel we have a fondness for a few too many near-trivial
> one-liners that make libraries bigger and harder to navigate, without
> really adding much expressivity.

I have a lot of sympathy for this view.  Hence, only

   +0.3

from me.

Cheers,
	Simon




More information about the Libraries mailing list