[Haskell-beginners] Stack space overflow: using strict accumulator still fails
Hugo Ferreira
hmf at inescporto.pt
Mon Oct 31 23:12:03 CET 2011
On 10/31/2011 09:14 PM, Daniel Fischer wrote:
> On Monday 31 October 2011, 10:36:53, Hugo Ferreira wrote:
>> Hello,
>>
>> Apologies for the late reply but I had to prep the code.
>>
>> On 10/28/2011 09:43 AM, Daniel Fischer wrote:
>>> 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).
>>
>> Not really. That's pretty much the indentation I am using. I actually
>> had additional trace statements. Can you please tell me what's wrong?
>
> You're not having the 'where's on their own lines ;)
You mean, I have to use something like:
where
(correct,_) = Z.cursor z
instead of
where (correct,_) = Z.cursor z
I googled the rules and found
http://en.wikibooks.org/wiki/Haskell/Indentation. Doesn't seem to be a
requirement.
> Seriously: I hadn't bothered to view it in fixed-width font and
> underestimated how much my mail client compresses contiguous whitespace.
>
>>
>>> Can you post the complete source for diagnosis?
>>
>> I have attached the code + cabal files. I think that is all that is
>> required. I am not sending the training data because it is too large
>> (+7 Mega bytes). That is available at http://nlpwp.org/nlpwp-data.zip
>
> Been a bugger to hunt down, but I finally found it.
> The culprit is *drumroll, ba-dum tish*:
> a one-character typo in Data.List.Zipper.
> foldlz' isn't. The recursive call is to foldlz, not foldlz'.
>
Now I am baffled B-(
The package docs state:
foldlz' is foldlz with a strict accumulator
Why would/should one not use the strict version here?
What do you mean when you say "recursive call"?
TIA,
Hugo F.
More information about the Beginners
mailing list