Ticket #1752: fibsquares.hs

File fibsquares.hs, 450 bytes (added by guest, 7 years ago)

leaky!

Line 
1module Main where
2
3fibs a b = a : fibs b (a+b)
4
5odds (x:xs) = evens xs
6evens (x:xs) = x : odds xs
7
8square x = x*x
9sumSucc xs = zipWith (+) xs (tail xs)
10
11main = spaceleak
12
13spaceleak = 
14    mapM_ print $ zip [0..] $ takeWhile id $
15    zipWith (==) (odds $ fibs 0 1) $ 
16    sumSucc $ map square $ fibs 0 1
17
18noleak =
19    mapM_ print $ zip [0..] $ takeWhile id $
20    zipWith (==) (odds $ fibs 0 1)
21    (sumSucc $ map square $ fibs 0 1)