1e2aa92e7ef860d7098c1f1187563923aa13f383
[ghc-hetmet.git] / ghc / tests / programs / hill_stk_oflow / Main.hs
1 {- Without strictness analysis, this program runs in constants
2    space, giving non-termination.
3    With strictness analysis, the recursive call to final is not
4    a tail call, so stack overflow results.
5 -}
6
7 module Main where
8
9 main = print (final nums)
10
11 nums :: [Int]
12 nums = fromn 1
13
14 fromn :: Int -> [Int]
15 fromn n = n : fromn (n+1)
16
17 final :: [Int] -> Int
18 final (a:l) = seqq (force a) (final l)
19
20 force :: Int -> Int
21 force a | a == a = a
22
23 seqq :: Int -> Int -> Int
24 seqq a b | a == a = b