
Hello, Have a stack overflow but cannot see why (read up on [1], may be missing something trivial). Once again using the http://nlpwp.org/ book code. If I call the following function, it blows its top: scoreRule :: TransformationRule -> Z.Zipper (Tag, Tag) -> Int scoreRule r z = nCorrect - nIncorrect where (nCorrect, nIncorrect) = scoreRule_ r z scoreRule_ :: TransformationRule -> Z.Zipper (Tag, Tag) -> (Int, Int) scoreRule_ r = Z.foldlz' (scoreElem r) (0, 0) where scoreElem r s@(nCorrect, nIncorrect) z = case ruleApplication r z of Just tag -> if tag == correct then (nCorrect + 1, nIncorrect) else (nCorrect, nIncorrect + 1) Nothing -> s where (correct, _) = Z.cursor z however I see that the eager version of foldlz is being used. I also though that maybe ruleApplication my not be executing immediately. But I cannot see why (added definition below for reference). Can anyone point out why this is not strict? TIA, Hugo F. [1] http://www.haskell.org/haskellwiki/Stack_overflow ruleApplication :: TransformationRule -> Z.Zipper (Tag, Tag) -> Maybe Tag ruleApplication (NextTagRule (Replacement old new) next) z = do (_, proposed) <- Z.safeCursor z (_, nextProposed) <- rightCursor z if proposed == old && nextProposed == next then Just new else Nothing ruleApplication (PrevTagRule (Replacement old new) prev) z = do (_, proposed) <- Z.safeCursor z (_, prevProposed) <- leftCursor z if proposed == old && prevProposed == prev then Just new else Nothing ruleApplication (SurroundTagRule (Replacement old new) prev next) z = do (_, proposed) <- Z.safeCursor z (_, nextProposed) <- rightCursor z (_, prevProposed) <- leftCursor z if proposed == old && prevProposed == prev && nextProposed == next then Just new else Nothing