@@ -24,13 +24,28 @@ isRight e = case e of { Right _ -> True ; _ -> False }
2424
2525-- Keep only the values held in `Left` values.
2626lefts : [Either a b] -> [a]
27−lefts es = List.filter isLeft es
27+lefts es = List.foldr consLeft [] es
2828
2929-- Keep only the values held in `Right` values.
3030rights : [Either a b] -> [b]
31−rights es = List.filter isRight es
31+rights es = List.foldr consRight [] es
3232
3333-- Split into two lists, lefts on the left and rights on the right. So we
3434-- have the equivalence: `(partition es == (lefts es, rights es))`
3535partition : [Either a b] -> ([a],[b])
36−partition es = List.partition isLeft es
36+partition es = List.foldr consEither ([],[]) es
37+
38+consLeft e vs =
39+ case e of
40+ Left v -> v::vs
41+ Right _ -> vs
42+
43+consRight e vs =
44+ case e of
45+ Left _ -> vs
46+ Right v -> v::vs
47+
48+consEither e (ls,rs) =
49+ case e of
50+ Left l -> (l::ls,rs)
51+ Right r -> (ls,r::rs)