[Haskell-cafe] Small optimisation question

Stefan O'Rear stefanor at cox.net
Sat Nov 17 11:04:20 EST 2007

On Sat, Nov 17, 2007 at 04:01:34PM +0000, Andrew Coppin 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.)

The compiler will generate calls to concat and replicate.

Stefan, who is pretty sure he has a proposal for generalized folding

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20071117/60729b7d/attachment.bin

More information about the Haskell-Cafe mailing list