ref: b2ddf4524fe751e90f2eb3e1ce5000446835f141
parent: 9570961f013d1ed2d728e82029c824e36863c67b
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Thu Aug 24 09:30:54 EDT 2023
Neater definitions.
--- a/lib/Data/Either.hs
+++ b/lib/Data/Either.hs
@@ -5,8 +5,5 @@
data Either a b = Left a | Right b
either :: forall a b r . (a -> r) -> (b -> r) -> Either a b -> r
-either fa fb arg =
- case arg of
- Left a -> fa a
- Right b -> fb b
-
+either f _ (Left a) = f a
+either _ f (Right b) = f b
--- a/lib/Data/Maybe.hs
+++ b/lib/Data/Maybe.hs
@@ -5,22 +5,16 @@
data Maybe a = Nothing | Just a
maybe :: forall a r . r -> (a -> r) -> Maybe a -> r
-maybe r f arg =
- case arg of
- Nothing -> r
- Just a -> f a
+maybe r _ Nothing = r
+maybe _ f (Just a) = f a
fromMaybe :: forall a . a -> Maybe a -> a
-fromMaybe a arg =
- case arg of
- Nothing -> a
- Just x -> x
+fromMaybe a Nothing = a
+fromMaybe _ (Just a) = a
fmapMaybe :: forall a b . (a -> b) -> Maybe a -> Maybe b
-fmapMaybe f am =
- case am of
- Nothing -> Nothing
- Just a -> Just (f a)
+fmapMaybe _ Nothing = Nothing
+fmapMaybe f (Just a) = Just (f a)
catMaybes :: forall a . [Maybe a] -> [a]
catMaybes mxs = [ x | Just x <- mxs ]
--
⑨