summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run/T4830.hs
blob: e345ffc9cdf38dadd955fb1274b01da3c06d8e14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- Compile with O2; SpecConstr should fire nicely
-- and eliminate all allocation in inner loop

module Main where

foo :: Int -> Maybe (Double,Double) -> Double
foo _ Nothing      = 0
foo 0 (Just (x,y)) = x+y
foo n (Just (x,y)) = let r = f x y in r `seq` foo (n-1) (Just r)
  where
    f x y | x <= y    = (x,y)
          | otherwise = (y,x)

main = print (foo 1000000 (Just (1,2)))