[Haskell-cafe] First call to putStr takes far more time than subsequent calls

Roman Cheplyaka roma at ro-che.info
Fri Jul 10 06:23:49 UTC 2015

On 10/07/15 04:34, Ben Gunton wrote:
> When a module is imported, or used for the first time, are there things
> that are not fully evaluated? 

Evaluation isn't tied to modules in any way. Modules are namespaces;
they are strictly compile-time entities.

Imagine that in your module you define at the top level

  fac10 :: Integer
  fac10 = product [1..10]

This is known as CAF, a constant applicative form. If you never demand
the value of fac10 in your program, it will never get evaluated. If you
do demand the value of fac10, it will be evaluated the first time, and
then fac10 will be modified to point to the actual value instead of a
thunk, so all the subsequent calls will be much faster.

Now, I suspect that there may be something like fac10 in Data.Fixed or
perhaps one of its dependencies. It doesn't even have to be defined in
the code: during optimization, a lot of things become CAFs when ghc
finds something that looks like a constant and floats it out to the top


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150710/81de7b2c/attachment.sig>

More information about the Haskell-Cafe mailing list