[Haskell-cafe] Thunks and GHC pessimisation

Joachim Breitner mail at joachim-breitner.de
Sun Feb 24 19:12:24 CET 2013


Hi,

I believe, without checking, that

Am Sonntag, den 24.02.2013, 17:49 +0000 schrieb Tom Ellis:
> many :: () -> [Int]
> many () = [1..million]

is indeed called many times. The problem is that [1..million] is not
dependent on the parameter, so GHC will float it out to a top level
declaration, and hence share it between the multiple calls to many.

You should try:

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

Greetings,
Joachim

(Maybe I should continue to work on http://arxiv.org/abs/1106.3478 and
related ideas, like annotating thunks in the code as unshareable... or
does this mostly occur in small example programs like this?)

-- 
Joachim "nomeata" Breitner
Debian Developer
  nomeata at debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C
  JID: nomeata at joachim-breitner.de | http://people.debian.org/~nomeata

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130224/db0f3f84/attachment.pgp>


More information about the Haskell-Cafe mailing list