A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/src/Data-Either.html below:

Data/Either.hs



#ifdef __GLASGOW_HASKELL__

#endif















module Data.Either (
   Either(..),
   either,           
   lefts,            
   rights,           
   partitionEithers, 
 ) where

#include "Typeable.h"

#ifdef __GLASGOW_HASKELL__
import GHC.Base
import GHC.Show
import GHC.Read
#endif

import Data.Typeable

#ifdef __GLASGOW_HASKELL__



data  Either a b  =  Left a | Right b
  deriving (Eq, Ord, Read, Show)

instance Functor (Either a) where
    fmap _ (Left x) = Left x
    fmap f (Right y) = Right (f y)

instance Monad (Either e) where
    return = Right
    Left  l >>= _ = Left l
    Right r >>= k = k r




either                  :: (a -> c) -> (b -> c) -> Either a b -> c
either f _ (Left x)     =  f x
either _ g (Right y)    =  g y
#endif  /* __GLASGOW_HASKELL__ */

INSTANCE_TYPEABLE2(Either,eitherTc,"Either")




lefts   :: [Either a b] -> [a]
lefts x = [a | Left a <- x]




rights   :: [Either a b] -> [b]
rights x = [a | Right a <- x]






partitionEithers :: [Either a b] -> ([a],[b])
partitionEithers = foldr (either left right) ([],[])
 where
  left  a ~(l, r) = (a:l, r)
  right a ~(l, r) = (l, a:r)




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4