blob: f68e7ecbcbda8dfb1a39b14152e81d5338fa277b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
-- The direct implementation of drop and dropWhile operates in O(1) space.
-- This regression test asserts that potential fusion rules for dropWhile/drop
-- maintain that property for the fused pipelines in dropWhile2 and drop2 (which
-- are marked NOINLINE for that purpose).
-- #23021 was opened because we had fusion rules in place that did not maintain
-- this property.
dropWhile2 :: Int -> [Int] -> [Int]
dropWhile2 n = dropWhile (< n) . dropWhile (< n)
{-# NOINLINE dropWhile2 #-}
drop2 :: Int -> [Int] -> [Int]
drop2 n = drop n . drop n
{-# NOINLINE drop2 #-}
main :: IO ()
main = do
let xs = [0..9999999]
print $ last $ dropWhile2 0 xs
print $ last $ dropWhile2 1 xs
print $ last $ dropWhile2 2 xs
print $ last $ dropWhile2 3 xs
print $ last $ dropWhile2 4 xs
print $ last $ dropWhile2 5 xs
print $ last $ drop2 0 xs
print $ last $ drop2 1 xs
print $ last $ drop2 2 xs
print $ last $ drop2 3 xs
print $ last $ drop2 4 xs
print $ last $ drop2 5 xs
|