inside the GHC code generator

Bulat Ziganshin bulat.ziganshin at
Fri Feb 24 13:50:56 EST 2006

Hello Lemmih,

Friday, February 24, 2006, 8:55:37 PM, you wrote:

>> x :: ![Int]
>> translates to the
>> data StrictList a = Nil | Cons a !(StrictList a)
>> x :: !(StrictList a)

L> Let's try this:

L> x :: ![Int] -> Int

L> It would translate to something like this:

L> mkStrictList :: [a] -> StrictList a
L> x = xStrict . mkStrictList
L> xStrict = ...

L> Wouldn't it be very expensive to strictify the list?

yes, it would. but evaluating list as lazy one on EACH repetition of
some loop will cost much more. just for example - i found that the

repeat 6666666 (putStr (replicate 15 ' '))

works several times slower than

repeat (10^8) (putChar ' ')

if argument of putStr will be evaluated only one time then much of
difference will gone. of course, that is just benchmark. but there are
cases when i prefer to work with strict datastructures and specialize
my functions accordingly. typically it's the cases where time/space
are really critical

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at

More information about the Glasgow-haskell-users mailing list