Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Fwd: Stuck in debug of loop detection (Lev Broido) 2. Re: Stack space overflow: using strict accumulator still fails (Daniel Fischer) 3. Re: Stack space overflow: using strict accumulator still fails (Hugo Ferreira) 4. Re: Stack space overflow: using strict accumulator still fails (Hugo Ferreira) 5. Re: Stack space overflow: using strict accumulator still fails (Daniel Fischer) 6. Re: Stack space overflow: using strict accumulator still fails (Hugo Ferreira) 7. Re: Stack space overflow: using strict accumulator still fails (Daniel Fischer) 8. Re: Stack space overflow: using strict accumulator still fails (Hugo Ferreira) ---------------------------------------------------------------------- Message: 1 Date: Mon, 31 Oct 2011 15:24:02 +0200 From: Lev Broido <lev.bro...@gmail.com> Subject: [Haskell-beginners] Fwd: Stuck in debug of loop detection To: beginners@haskell.org Message-ID: <CAB=60u7zy2q5fbnhvz8fanhw8njerexe4nyrh41hc-f8q6c...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" ---------- Forwarded message ---------- From: Lev Broido <lev.bro...@gmail.com> Date: Mon, Oct 31, 2011 at 2:31 PM Subject: Stuck in debug of loop detection To: beginners@haskell.org, haskell-c...@haskell.org Hi I am playing around with building graph using 'tying the knote' technique , according to rule a is child of b iff predicate a b == true Additional step is to detect loops in graph to enable it's print . Then I am using graph traversal to detect loops prior to calling show . For now I am stuck debugging loop detection . I am using 'trace' for a first time and I am not sure I am fully understanding it's behavior In additional I tried to make all calculations strict for debug . Can you please provide tips / review code . My code is at http://pastebin.com/5RvQ42z2 Thanks, Lev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111031/26ffa430/attachment-0001.htm> ------------------------------ Message: 2 Date: Mon, 31 Oct 2011 22:14:28 +0100 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] Stack space overflow: using strict accumulator still fails To: Hugo Ferreira <h...@inescporto.pt> Cc: beginners@haskell.org Message-ID: <201110312214.28261.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="utf-8" 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 ;) 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'. ------------------------------ Message: 3 Date: Mon, 31 Oct 2011 22:12:03 +0000 From: Hugo Ferreira <h...@inescporto.pt> Subject: Re: [Haskell-beginners] Stack space overflow: using strict accumulator still fails To: Daniel Fischer <daniel.is.fisc...@googlemail.com> Cc: beginners@haskell.org Message-ID: <4eaf1d33.8070...@inescporto.pt> Content-Type: text/plain; charset=UTF-8; format=flowed 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. ------------------------------ Message: 4 Date: Mon, 31 Oct 2011 22:16:55 +0000 From: Hugo Ferreira <h...@inescporto.pt> Subject: Re: [Haskell-beginners] Stack space overflow: using strict accumulator still fails To: Daniel Fischer <daniel.is.fisc...@googlemail.com> Cc: beginners@haskell.org Message-ID: <4eaf1e57.1000...@inescporto.pt> Content-Type: text/plain; charset=UTF-8; format=flowed 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 ;) > 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'. > BTW, I changed foldlz' to foldlz and used (!) but still get the stack overflow. Need I do anything else? TIA, Hugo F. ------------------------------ Message: 5 Date: Mon, 31 Oct 2011 23:31:21 +0100 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] Stack space overflow: using strict accumulator still fails To: Hugo Ferreira <h...@inescporto.pt> Cc: beginners@haskell.org Message-ID: <201110312331.21118.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="utf-8" On Monday 31 October 2011, 23:12:03, Hugo Ferreira wrote: > You mean, I have to use something like: > > where > (correct,_) = Z.cursor z > > instead of > > where (correct,_) = Z.cursor z Yes. > > I googled the rules and found > http://en.wikibooks.org/wiki/Haskell/Indentation. Doesn't seem to be a > requirement. Hence the ";)". > > > > 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? Because there's a typo in the implementation (notified the maintainer). > What do you mean when you say "recursive call"? Let's look at lists first. The specification in the standard is foldl f z [] = z foldl f z (x:xs) = foldl f (f z x) xs ^^^^^ recursive call to foldl Very similar for the list zipper, we have foldlz :: (b -> Zipper a -> b) -> b -> Zipper a -> b foldlz f x z | endp z = x | otherwise = foldlz f (f x z) (right z) ^^^^^^ And for foldlz', the intention was foldlz' :: (b -> Zipper a -> b) -> b -> Zipper a -> b foldlz' f x z | endp z = x | otherwise = acc `seq` foldlz' f acc (right z) where acc = f x z but in the otherwise branch, the ' has been omitted, so instead of recursively calling itself with the new accumulator, it calls foldlz. ------------------------------ Message: 6 Date: Mon, 31 Oct 2011 22:42:30 +0000 From: Hugo Ferreira <h...@inescporto.pt> Subject: Re: [Haskell-beginners] Stack space overflow: using strict accumulator still fails To: Daniel Fischer <daniel.is.fisc...@googlemail.com> Cc: beginners@haskell.org Message-ID: <4eaf2456.2070...@inescporto.pt> Content-Type: text/plain; charset=UTF-8; format=flowed On 10/31/2011 10:31 PM, Daniel Fischer wrote: > On Monday 31 October 2011, 23:12:03, Hugo Ferreira wrote: >> You mean, I have to use something like: >> >> where >> (correct,_) = Z.cursor z >> >> instead of >> >> where (correct,_) = Z.cursor z > > Yes. > >> >> I googled the rules and found >> http://en.wikibooks.org/wiki/Haskell/Indentation. Doesn't seem to be a >> requirement. > > Hence the ";)". > I see. B-) > >>> >>> 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? > > Because there's a typo in the implementation (notified the maintainer). > >> What do you mean when you say "recursive call"? > > Let's look at lists first. > > The specification in the standard is > > foldl f z [] = z > foldl f z (x:xs) = foldl f (f z x) xs > ^^^^^ > recursive call to foldl > > Very similar for the list zipper, we have > > foldlz :: (b -> Zipper a -> b) -> b -> Zipper a -> b > foldlz f x z > | endp z = x > | otherwise = foldlz f (f x z) (right z) > ^^^^^^ > > And for foldlz', the intention was > > foldlz' :: (b -> Zipper a -> b) -> b -> Zipper a -> b > foldlz' f x z > | endp z = x > | otherwise = acc `seq` foldlz' f acc (right z) > where acc = f x z > > but in the otherwise branch, the ' has been omitted, so instead of > recursively calling itself with the new accumulator, it calls foldlz. > Ok, I though the typo was on my side. So you have found a bug. My hat is off to you. Thanks, Hugo F. ------------------------------ Message: 7 Date: Mon, 31 Oct 2011 23:46:43 +0100 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] Stack space overflow: using strict accumulator still fails To: Hugo Ferreira <h...@inescporto.pt> Cc: beginners@haskell.org Message-ID: <201110312346.43484.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="utf-8" On Monday 31 October 2011, 23:16:55, Hugo Ferreira wrote: > BTW, I changed foldlz' to foldlz and used (!) No good. foldlz needs (in this case) the laziness in the accumulator. > but still get the stack overflow. Need I do anything else? You can patch your ListZipper (cabal unpack ListZipper; correct the typo; increment version number in ListZipper.cabal; cabal install), then you can use foldlz' with a strict accumulator. Or you can use foldlz with a lazy accumulator, doesn't make much difference for the brown corpus. Also, in tokenTagFreqs, replace M.insertWith (twice) with M.insertWith', you're filling your maps with thunks as is. Evaluating entries on the spot reduces time and memory requirements. ------------------------------ Message: 8 Date: Mon, 31 Oct 2011 22:59:47 +0000 From: Hugo Ferreira <h...@inescporto.pt> Subject: Re: [Haskell-beginners] Stack space overflow: using strict accumulator still fails To: Daniel Fischer <daniel.is.fisc...@googlemail.com> Cc: beginners@haskell.org Message-ID: <4eaf2863.2070...@inescporto.pt> Content-Type: text/plain; charset=UTF-8; format=flowed On 10/31/2011 10:46 PM, Daniel Fischer wrote: > On Monday 31 October 2011, 23:16:55, Hugo Ferreira wrote: >> BTW, I changed foldlz' to foldlz and used (!) > > No good. foldlz needs (in this case) the laziness in the accumulator. > >> but still get the stack overflow. Need I do anything else? > > You can patch your ListZipper (cabal unpack ListZipper; correct the typo; > increment version number in ListZipper.cabal; cabal install), then you can > use foldlz' with a strict accumulator. Or you can use foldlz with a lazy > accumulator, doesn't make much difference for the brown corpus. > Hmmm.... how so? I get stack overflow. You mean use the RTS options to increase memory. > Also, in tokenTagFreqs, replace M.insertWith (twice) with M.insertWith', > you're filling your maps with thunks as is. Evaluating entries on the spot > reduces time and memory requirements. > Will report this to the book's authors. Thanks once again, Hugo F. ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 40, Issue 50 *****************************************