2013-01-09 10:07:46 +00:00
|
|
|
|
2013-03-10 08:54:37 +00:00
|
|
|
module Either where
|
|
|
|
|
2013-03-11 05:42:57 +00:00
|
|
|
import List
|
2013-03-10 08:54:37 +00:00
|
|
|
|
2013-01-09 10:07:46 +00:00
|
|
|
data Either a b = Left a | Right b
|
|
|
|
|
2013-02-07 18:54:21 +00:00
|
|
|
either : (a -> c) -> (b -> c) -> Either a b -> c
|
2013-01-09 10:07:46 +00:00
|
|
|
either f g e = case e of { Left x -> f x ; Right y -> g y }
|
|
|
|
|
2013-02-07 18:54:21 +00:00
|
|
|
|
2013-03-11 05:42:57 +00:00
|
|
|
isLeft : Either a b -> Bool
|
|
|
|
isLeft e = case e of { Left _ -> True ; _ -> False }
|
2013-02-07 18:54:21 +00:00
|
|
|
|
|
|
|
isRight : Either a b -> Bool
|
2013-01-09 10:07:46 +00:00
|
|
|
isRight e = case e of { Right _ -> True ; _ -> False }
|
|
|
|
|
2013-02-07 18:54:21 +00:00
|
|
|
|
2013-03-11 05:42:57 +00:00
|
|
|
--lefts : [Either a b] -> [a]
|
|
|
|
lefts es = List.filter isLeft es
|
2013-02-07 18:54:21 +00:00
|
|
|
|
2013-03-11 05:42:57 +00:00
|
|
|
--rights : [Either a b] -> [b]
|
|
|
|
rights es = List.filter isRight es
|
2013-01-09 10:07:46 +00:00
|
|
|
|
2013-03-11 05:42:57 +00:00
|
|
|
--partition : [Either a b] -> ([a],[b])
|
|
|
|
partition es = List.partition isLeft es
|