[Haskell-cafe] Thunks and GHC pessimisation

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sun Feb 24 19:41:40 CET 2013


On Sun, Feb 24, 2013 at 07:12:24PM +0100, Joachim Breitner wrote:
> You should try:
> 
> > million :: () -> Int
> > million _ = 10 ^ (6 :: Int)
> >
> > many :: () -> [Int]
> > many x = [1..million x]

Thanks Joachim, but that doesn't work either.

Tom


% cat thunkfail.hs 
{-# OPTIONS_GHC -fno-warn-unused-binds #-}

import Data.List

million :: () -> Int
million _ = 10 ^ (6 :: Int)
                             
many :: () -> [Int]
many x = [1..million x]

different_many :: () -> [Int]
different_many x = [1..million x]

twice :: (Int, Int)
twice = (foldl' (+) 0 (many ()), foldl' (+) 0 (many ()))
        
main :: IO ()
main = print twice
% ghc -O -fforce-recomp -Wall -Werror -rtsopts thunkfail.hs && ./thunkfail
% +RTS -M5M                      
[1 of 1] Compiling Main             ( thunkfail.hs, thunkfail.o )
Linking thunkfail ...
Heap exhausted;
Current maximum heap size is 5242880 bytes (5 MB);
use `+RTS -M<size>' to increase it.



More information about the Haskell-Cafe mailing list