summaryrefslogtreecommitdiff
path: root/testsuite/tests/simplCore/should_compile/T17724.hs
blob: a514a7f305251ec4d99ab0a1b2b8a04c42bbedd4 (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
26
-- The CSE pass implicitly requires bindings to be in argument order
-- or things can go wrong. This was the case in this example.
-- This code is extracted from containers' sequence-benchmarks and the gauge
-- package.
{-# language ExistentialQuantification #-}

module T17724 where

import Control.Exception (evaluate)

data Benchmarkable = forall a .
    Benchmarkable
      { allocEnv :: Int -> IO a
      , runRepeatedly :: a -> Int -> IO ()
      }

a, b :: Benchmarkable
a = nf (\(s,t) -> (,) <$> replicate s () <*> replicate t ()) (100,2500)
b = nf (\(s,t) -> (,) <$> replicate s () <*> replicate t ()) (2500,100)

nf :: (a -> b) -> a -> Benchmarkable
nf f0 x0 = Benchmarkable (const (return ())) (const (go f0 x0))
  where go f x n
          | n <= 0    = return ()
          | otherwise = evaluate (f x) >> go f x (n-1)