[Haskell-cafe] Question about STRef

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Thu Jan 26 11:42:06 UTC 2017

Thanks for pointing out this (Knuth's) nice test case.
I should use this as an exam question ...

Allocation and run-time can be reduced
by replacing  return (x3' + x4')
with  let x = (x3' + x4') in x `seq` return x
And, modifySTRef' *does* help.

I *do* notice a regression
(for the seq-ed and primed version)

ghc-8.0.2 : 2.6 GB alloc, 2.3 sec
ghc-6.10.4: 2.0 GB alloc, 1.7 sec

(measured on X5365  @ 3.00GHz )

Numbers are for total allocation,
residency is small  (it runs with  +RTS -H10k -A10k
but then the number of GCs goes up)

- J.

More information about the Haskell-Cafe mailing list