[Haskell-cafe] Small optimisation question
stefanor at cox.net
Sat Nov 17 11:17:49 EST 2007
On Sat, Nov 17, 2007 at 04:10:58PM +0000, Andrew Coppin wrote:
> Stefan O'Rear wrote:
>> 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?
>> The compiler will generate calls to concat and replicate.
> OK. I presume this is due to the fact that the result of executing an
> expression at compile-time could be arbitrarily large?
Yes, and it's not even guaranteed to terminate.
> Are there any buttons that can be twiddled to control this behaviour?
Not that I'm aware of, though you can hack something with RULEs
> For that matter, when I say "[4,7,2,9]", what does that compile into? Some
> data structures in memory? Or code to actually build said structures?
Both. A curious feature of the STG machine is that constructor thunks
and evaluated data are represented identically in memory.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20071117/f5c2f51e/attachment.bin
More information about the Haskell-Cafe