summaryrefslogtreecommitdiff
path: root/libraries/base/GHC
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2014-07-22 11:21:01 +0200
committerJoachim Breitner <mail@joachim-breitner.de>2014-07-22 11:21:01 +0200
commitb709f0a047dc036de15dc43d3b0ab88d3e32c5e6 (patch)
tree96d91eb93731674656b40bd83e36867ddaf595d5 /libraries/base/GHC
parent7aabfa6292c2469cf3250e006869273fb1b356ce (diff)
downloadhaskell-b709f0a047dc036de15dc43d3b0ab88d3e32c5e6.tar.gz
Make last a good consumer
Summary: Make last a good consumer simply by implementing it as foldl. This fixes Trac: #9339. Thanks to David Feuer for bringing it up. Test Plan: perf/should_run/T9339 + general validation Reviewers: austin Reviewed By: austin Subscribers: phaskell, simonmar, relrod, carter Differential Revision: https://phabricator.haskell.org/D86 Trac Issues: #9339
Diffstat (limited to 'libraries/base/GHC')
-rw-r--r--libraries/base/GHC/List.lhs7
1 files changed, 2 insertions, 5 deletions
diff --git a/libraries/base/GHC/List.lhs b/libraries/base/GHC/List.lhs
index e004ded1e8..9b6cc2eb19 100644
--- a/libraries/base/GHC/List.lhs
+++ b/libraries/base/GHC/List.lhs
@@ -83,11 +83,8 @@ last [x] = x
last (_:xs) = last xs
last [] = errorEmptyList "last"
#else
--- eliminate repeated cases
-last [] = errorEmptyList "last"
-last (x:xs) = last' x xs
- where last' y [] = y
- last' _ (y:ys) = last' y ys
+-- use foldl to allow fusion
+last = foldl (\_ x -> x) (errorEmptyList "last")
#endif
-- | Return all the elements of a list except the last one.