X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FUtil.lhs;h=af811104762c0fb7fc99252ee6755dc2a9945514;hb=893a3c0ad6c39caf71ac28af900733513e1f153e;hp=4058a97f3661227da681fc024654d51271004ce2;hpb=7251944b3932ebcef656efdf201edfd8121aea76;p=ghc-hetmet.git diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs index 4058a97..af81110 100644 --- a/compiler/utils/Util.lhs +++ b/compiler/utils/Util.lhs @@ -32,6 +32,7 @@ module Util ( -- * List operations controlled by another list takeList, dropList, splitAtList, split, + dropTail, -- * For loop nTimes, @@ -107,6 +108,15 @@ infixr 9 `thenCmp` %* * %************************************************************************ +These booleans are global constants, set by CPP flags. They allow us to +recompile a single module (this one) to change whether or not debug output +appears. They sometimes let us avoid even running CPP elsewhere. + +It's important that the flags are literal constants (True/False). Then, +with -0, tests of the flags in other modules will simplify to the correct +branch of the conditional, thereby dropping debug code altogether when +the flags are off. + \begin{code} ghciSupported :: Bool #ifdef GHCI @@ -599,6 +609,10 @@ splitAtList (_:xs) (y:ys) = (y:ys', ys'') where (ys', ys'') = splitAtList xs ys +-- drop from the end of a list +dropTail :: Int -> [a] -> [a] +dropTail n = reverse . drop n . reverse + snocView :: [a] -> Maybe ([a],a) -- Split off the last element snocView [] = Nothing