Isn't this tail recursive?

Bjorn Lisper lisper@it.kth.se
Wed, 13 Mar 2002 09:12:04 +0100 (MET)


Hal Daume III:
>Here's the basic idea.  Suppose we have the function:
>
>> sum [] acc = acc
>> sum (x:xs) acc = sum xs (acc+x)
>
>This is tail recursive, but not strict in the accumulator argument.
...

Just a nitpick here. sum is indeed strict in its second argument (given that
(+) is strict in its first argument). That is, sum l _|_ = _|_ for all
possible lists l.

It is of course possible that the compiler you use does not detect this and
generates nonstrict code.

But I think a decent strictness analyzer should detect this. Can the problem
be that + is overloaded in Haskell, so the compiler cannot assume any
semantical properties like strictness for it?

Björn Lisper