diff options
Diffstat (limited to 'compiler/utils')
-rw-r--r-- | compiler/utils/FastString.hs | 4 | ||||
-rw-r--r-- | compiler/utils/Util.hs | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/compiler/utils/FastString.hs b/compiler/utils/FastString.hs index f9fbeb0e6e..588486bf46 100644 --- a/compiler/utils/FastString.hs +++ b/compiler/utils/FastString.hs @@ -71,6 +71,7 @@ module FastString concatFS, consFS, nilFS, + isUnderscoreFS, -- ** Outputing hPutFS, @@ -603,6 +604,9 @@ uniqueOfFS (FastString u _ _ _) = u nilFS :: FastString nilFS = mkFastString "" +isUnderscoreFS :: FastString -> Bool +isUnderscoreFS fs = fs == fsLit "_" + -- ----------------------------------------------------------------------------- -- Stats diff --git a/compiler/utils/Util.hs b/compiler/utils/Util.hs index 84799aed0b..0c7bb4a189 100644 --- a/compiler/utils/Util.hs +++ b/compiler/utils/Util.hs @@ -30,7 +30,7 @@ module Util ( dropWhileEndLE, spanEnd, last2, - foldl1', foldl2, count, all2, + foldl1', foldl2, count, countWhile, all2, lengthExceeds, lengthIs, lengthIsNot, lengthAtLeast, lengthAtMost, lengthLessThan, @@ -705,6 +705,12 @@ count p = go 0 go !n (x:xs) | p x = go (n+1) xs | otherwise = go n xs +countWhile :: (a -> Bool) -> [a] -> Int +-- Length of an /initial prefix/ of the list satsifying p +countWhile p = go 0 + where go !n (x:xs) | p x = go (n+1) xs + go !n _ = n + {- @splitAt@, @take@, and @drop@ but with length of another list giving the break-off point: |