isLeft/isRight (Was: leftToMaybe/rightToMaybe)

Andreas Abel andreas.abel at ifi.lmu.de
Fri Aug 9 08:58:40 CEST 2013


Usually I start out writing such functions into Bool, but then end up 
generalizing them to Maybe, in this case

   isLeft :: Either a b -> Maybe a
   isLeft (Left a) = Just a
   isLeft Right{}  = Nothing

   etc.

If I really need a Bool, I can compose them with isJust/isNothing.

On 07.08.13 9:18 AM, Henning Thielemann wrote:
>
> On Wed, 7 Aug 2013, Erik de Castro Lopo wrote:
>
>> And while we're at it:
>>
>> isLeft :: Either a b -> Bool
>> isLeft (Left _) = True
>> isLeft (Right _) = False
>>
>> isRight :: Either a b -> Bool
>> isRight (Left _) = False
>> isRight (Right _) = True
>
> http://www.haskell.org/pipermail/libraries/2012-November/018709.html
> http://www.haskell.org/pipermail/libraries/2012-December/018716.html
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>

-- 
Andreas Abel  <><      Du bist der geliebte Mensch.

Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY

andreas.abel at ifi.lmu.de
http://www2.tcs.ifi.lmu.de/~abel/




More information about the Libraries mailing list