[Haskell-beginners] Stack space overflow: using strict accumulator still fails

Daniel Fischer daniel.is.fischer at googlemail.com
Fri Oct 28 10:43:56 CEST 2011


On Thursday 27 October 2011, 17:02:46, Hugo Ferreira wrote:
> But something seems to be wrong here. If I do:
> 
> scoreRule_ r zs = Z.foldlz' (scoreElem r) (0, 0) zs
>    where scoreElem r s z =
>            let (nCorrect, nIncorrect) = s in
>            case ruleApplication r z of
>              Just tag -> if tag == correct
>                          then (nCorrect+1, nIncorrect)
>                          else  (nCorrect, nIncorrect+1)
>              Nothing  -> (nCorrect, nIncorrect)
>            where c = Z.cursor z
>                  (correct,_) = c
> 
> it works correctly, however this does not work:
> 
> scoreRule_ r zs = Z.foldlz' (scoreElem r) (0, 0) zs
>    where scoreElem r (!nCorrect, !nIncorrect) z =
>            case ruleApplication r z of
>              Just tag -> if tag == correct
>                          then (nCorrect+1, nIncorrect)
>                          else (nCorrect, nIncorrect+1)
>              Nothing  -> (nCorrect, nIncorrect)
>            where c = Z.cursor z
>                  (correct,_) = c
> 
> I have been staring at this for some time now, but cannot
> understand why it does not work. Any ideas?

No. Looks perfectly okay (well, the indentation is wrong, but that's the 
same for the working version above and is probably due to the mail client).
Can you post the complete source for diagnosis?




More information about the Beginners mailing list