summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run/Conversions.hs
blob: 843272796531b14a8c144d20dbcae3e200ce0f2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{-# LANGUAGE BangPatterns #-}

-- | Tests that conversions between various primitive types (e.g.
-- Word, Double, etc) doesn't allocate.
module Main (main) where

import Data.Word

-- Repeatedly convert Words to Doubles
loop :: Floating a => Word -> a
loop n = go 0 0.0
  where
    go i !acc | i < n = go (i+1) (acc + fromIntegral i)
              | otherwise = acc
{-# SPECIALISE loop :: Word -> Float #-}
{-# SPECIALISE loop :: Word -> Double #-}

main :: IO ()
main = do
    print (loop 1000000 :: Float)
    print (loop 1000000 :: Double)