[Haskell-cafe] Flattening tail recursion?

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Fri Dec 10 11:35:57 EST 2004


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.

-- Ben



More information about the Haskell-Cafe mailing list