summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2013-08-16 11:15:33 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2013-08-19 09:46:10 +0100
commit098c7d1786d58bb9d2a6e1297707489488588d75 (patch)
tree466e3dbaf5882de594bb9af1d94e6ba620ee8ea1
parent83440fdc4f1b52b2f398326e0e86d4583afa433a (diff)
downloadhaskell-098c7d1786d58bb9d2a6e1297707489488588d75.tar.gz
Add a better implementation of dropTail, and use it
-rw-r--r--compiler/ghci/Linker.lhs2
-rw-r--r--compiler/utils/Util.lhs10
2 files changed, 10 insertions, 2 deletions
diff --git a/compiler/ghci/Linker.lhs b/compiler/ghci/Linker.lhs
index 45bc9d56c9..192df2ee57 100644
--- a/compiler/ghci/Linker.lhs
+++ b/compiler/ghci/Linker.lhs
@@ -637,7 +637,7 @@ getLinkDeps hsc_env hpt pls replace_osuf span mods
adjust_ul new_osuf (DotO file) = do
MASSERT(osuf `isSuffixOf` file)
- let file_base = reverse (drop (length osuf + 1) (reverse file))
+ let file_base = dropTail (length osuf + 1) file
new_file = file_base <.> new_osuf
ok <- doesFileExist new_file
if (not ok)
diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs
index dd947ffd93..5c82c757aa 100644
--- a/compiler/utils/Util.lhs
+++ b/compiler/utils/Util.lhs
@@ -574,7 +574,15 @@ splitAtList (_:xs) (y:ys) = (y:ys', ys'')
-- drop from the end of a list
dropTail :: Int -> [a] -> [a]
-dropTail n = reverse . drop n . reverse
+-- Specification: dropTail n = reverse . drop n . reverse
+-- Better implemention due to Joachim Breitner
+-- http://www.joachim-breitner.de/blog/archives/600-On-taking-the-last-n-elements-of-a-list.html
+dropTail n xs
+ = go (drop n xs) xs
+ where
+ go (_:ys) (x:xs) = x : go ys xs
+ go _ _ = [] -- Stop when ys runs out
+ -- It'll always run out before xs does
snocView :: [a] -> Maybe ([a],a)
-- Split off the last element