on master help sign in
use liftA2 to implement zipWith for Maybe and Either
3f04ad4Michael Morgan
libs/contrib/Interfaces/Zippable.idr+2−6
@@ -35,14 +35,10 @@ unzip3 : Functor t => t (a, b, c) -> (t a, t b, t c)
35unzip3 xs = (map fst xs, unzip (map snd xs))
35unzip3 xs = (map fst xs, unzip (map snd xs))
36
36
37Zippable Maybe where
37Zippable Maybe where
38− zipWith f Nothing _ = Nothing
38+ zipWith = liftA2
39− zipWith f (Just x) Nothing = Nothing
40− zipWith f (Just x) (Just y) = Just (f x y)
41
39
42Zippable (Either a) where
40Zippable (Either a) where
43− zipWith f (Left lx) _ = Left lx
41+ zipWith = liftA2
44− zipWith f (Right x) (Left ly) = Left ly
45− zipWith f (Right x) (Right y) = Right (f x y)
46
42
47Zippable List where
43Zippable List where
48 zipWith = Prelude.List.zipWith
44 zipWith = Prelude.List.zipWith