Christopher Sharpe writes:
> Hi,
> Could anyone tell me why "longTest", which uses a parser "p"
> which I _thought_ was tail-recursive gives "Control Stack
> overflow"? (Program is attached).
>
> Thanks in advance!
>
> [...]
>
> p s = do c <- item
> p (c:s)
> +++ return s
The (+++ return s) is applied on the way back, and prevents tail
recursion.
You and I know that the innermost (+++ return s) matters and all the
others don't. The difficult part is to express that knowledge in a
way that the Hugs optimiser can use. Even then, I don't think many
parsers would benefit from it, because most parsers recurse more
shallowly but with branching.
Regards,
Tom