summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libraries/base/Data/Maybe.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/libraries/base/Data/Maybe.hs b/libraries/base/Data/Maybe.hs
index d8aad53b9e..5f5d5ac910 100644
--- a/libraries/base/Data/Maybe.hs
+++ b/libraries/base/Data/Maybe.hs
@@ -228,9 +228,12 @@ maybeToList (Just x) = [x]
-- >>> maybeToList $ listToMaybe [1,2,3]
-- [1]
--
-listToMaybe :: [a] -> Maybe a
-listToMaybe [] = Nothing
-listToMaybe (a:_) = Just a
+listToMaybe :: [a] -> Maybe a
+listToMaybe = foldr (const . Just) Nothing
+{-# INLINE listToMaybe #-}
+-- We define listToMaybe using foldr so that it can fuse via the foldr/build
+-- rule. See #14387
+
-- | The 'catMaybes' function takes a list of 'Maybe's and returns
-- a list of all the 'Just' values.