[Haskell-cafe] Flattening tail recursion?

Jules Bean jules at jellybean.co.uk
Fri Dec 10 14:04:02 EST 2004


On 10 Dec 2004, at 16:35, Ben Rudiak-Gould wrote:

> Jules Bean wrote:
>
>> On 10 Dec 2004, at 15:34, Robert Dockins wrote:
>>
>>> So it should get "flattened," but it still doesn't run in constant 
>>> space because the "x" parmeter isn't strict, so it will accumulate a 
>>> bunch of closures like (((((((0)+1)+1)+1)+1)+1).... To make it 
>>> strict, do something like this:
>>>
>>
>> Isn't this what the strictness analyser is for? Doesn't GHC know that 
>> + for Int is strict in both arguments, and therefore it shouldn't 
>> accumulate a great big thunk like that?
>
>
> It doesn't know that about (+) :: Num a => a -> a -> a. The original 
> poster's code didn't mention Int anywhere, so GHC probably had to 
> assume the worst.
>

Forcing it to Int doesn't help though :(

Jules



More information about the Haskell-Cafe mailing list