[Haskell-cafe] Small optimisation question

Lennart Augustsson lennart at augustsson.net
Sat Nov 17 18:11:07 EST 2007

There's no "the compiler". :)  There are many compilers.  I don't know of
any that evaluate those expressions at compile time, but it's certainly not
forbidden.  Nor would it be exceedingly hard to implement.
But it's not too bad to do it at run time either, because it will (most
likely) only be evaluated once at run time.

  -- Lennart

On Nov 17, 2007 4:01 PM, Andrew Coppin <andrewcoppin at btinternet.com> wrote:

> Suppose I write something like this:
>  foo :: [Int]
>  foo = concat (replicate 4 [4,7,2,9])
> The value of "foo" is completely determined at compile-time. So, will
> the compiler generate calls to concat and replicate, or will it just
> insert a large list constant here?
> Obviously, once somebody has completely examined the contents of "foo",
> after that point it won't matter either way. I'm just curiose.
> Concatinating some strings is cheap; I sometimes write constructs like
> the above using much more expensive operations. (Expensive in time; the
> space taken up by the result isn't that great.)
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071117/791eed4e/attachment.htm

More information about the Haskell-Cafe mailing list