Update Trac ticket URLs to point to GitLab
[ghc.git] / testsuite / tests / perf / should_run / T5549.hs
1 module Main where
2 -- See #5549
3 -- The issue here is allocating integer constants inside a loop
4
5
6 lcs3 :: Eq a => [a] -> [a] -> [a]
7 lcs3 a b = fst $ aux (a, length a) (b, length b)
8 where
9 aux (_,0) _ = ([],0)
10 aux _ (_,0) = ([],0)
11 aux (a@(ha:as),la) (b@(hb:bs), lb)
12 | ha == hb = let (s,n) = aux (as,la-1) (bs,lb-1) in (ha : s, n+1)
13 | otherwise =
14 let (sa,na) = aux (as,la-1) (b,lb)
15 (sb,nb) = aux (a,la) (bs,lb-1) in
16 if na > nb then (sa,na) else (sb,nb)
17
18 f :: Integer -> Integer -> Integer
19 f acc 0 = acc
20 f acc n = g (acc + 1) (n-1)
21
22 g :: Integer -> Integer -> Integer
23 g acc 0 = acc
24 g acc n = f (acc -1) (n-1)
25
26 main = do putStrLn . show $ f 0 100000000
27 putStrLn . show $ lcs3 [1..20] [10..20]