summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run/T149_A.hs
blob: dd745460c05835daa96256fc7b1c49363df64b62 (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
module Main (main) where

-- See Trac #149

-- Curently (with GHC 7.0) the CSE works, just,
-- but it's delicate.


import System.CPUTime

main :: IO ()
main = print $ playerMostOccur1 [1..m]

m :: Int
m = 22

playerMostOccur1 :: [Int] -> Int
playerMostOccur1 [a] = a
playerMostOccur1 (x:xs)
 | numOccur x (x:xs) > numOccur (playerMostOccur1 xs) xs = x
 | otherwise = playerMostOccur1 xs

numOccur :: Int -> [Int] -> Int
numOccur i is = length $ filter (i ==) is