summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run/T7436b.hs
blob: e5f09aba9bd093b898bd50967e2cd349942bd451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{-# LANGUAGE DeriveFunctor #-}
-- A variation on T7436 that tests a derived Functor instance.
module Main where

data List a = Nil | Cons a (List a)
    deriving Functor

mkList :: Int -> List Int
mkList 0 = Nil
mkList n = Cons n (mkList (n-1))

sumList :: List Int -> Int
sumList = go 0
  where
    go a Nil = a
    go a (Cons n ns) = a `seq` go (a+n) ns

main :: IO ()
main = print $ sumList . fmap id $ mkList n
  where n = 40000