haskell - GHCi Debugger not hitting breakpoints recursively: Why, and what's the solution? -


i have simple recursive program doesn't quite work. i'm trying use ghci debugger figure out what's going on. set breakpoints on lines of functions recurse, progress , shaded, , catches first few. when second line of progress, every invocation of :continue drops me on same line of code, though i'm calling recurse , shaded there , expecting breakpoints work. here's code:

import system.environment  type pos = (int,int)  type acc = ([[pos]], [pos])  main =   getargs >>= putstrln . show . length . combos . read . head  combos n = recurse n [] (allpos n) []  recurse :: int -> [[pos]] -> [pos] -> [pos] -> [[pos]] recurse n done avail inprog    | length inprog == n = inprog:done    | null avail = done    | otherwise = fst $ foldr (progress n inprog) (done,avail) avail  progress :: int -> [pos] -> pos -> acc -> acc progress n inprog pos (done, avail)  =   (recurse n done (filter (not . shaded pos) remain) (pos:inprog), remain)   remain = tail avail  allpos n =  [ (i,j) | <- [0..n-1], j <- [0..n-1] ]  shaded :: pos -> pos -> bool shaded (i,j) (k,l) =   k ==   || l == j   || k+l == i+j   || k-l == i-j   || abs (k-i) < 3 && abs (l-j) < 3 

why ghci debugger not stop on breakpoints in functions called progress? there "non-reentrancy" turning them off? how can debugger break on every recursive call these functions?

ghci version 7.8.4

update: suspect may have cached results, it's not obvious me these functions have been called same arguments twice. bug in code?

i think working expected, have take account lazy evaluation.

if break @ guard lines in recurse (lines 13 -- 15) , call recurse in progress (line 19) you'll see pattern when program run :main 2:

stopped @ prog0.hs:13:6-23   - recurse stopped @ prog0.hs:14:6-15   - recurse stopped @ prog0.hs:15:18-67  - recurse, call foldr progress stopped @ prog0.hs:19:3-74   - in progress, pos = (1,1) stopped @ prog0.hs:19:3-74   - in progress, pos = (1,0) stopped @ prog0.hs:19:3-74   - in progress, pos = (0,1) stopped @ prog0.hs:19:3-74   - in progress, pos = (0,0) stopped @ prog0.hs:13:6-23   - in recurse stopped @ prog0.hs:14:6-15 stopped @ prog0.hs:13:6-23   - in recurse stopped @ prog0.hs:14:6-15    stopped @ prog0.hs:13:6-23   - in recurse stopped @ prog0.hs:14:6-15   stopped @ prog0.hs:13:6-23   - in recurse stopped @ prog0.hs:14:6-15 

however, if change progress force result:

import control.deepseq  progress n inprog pos (done, avail)  = let   result = (recurse n done (filter (not . shaded pos) remain) (pos:inprog), remain)   in deepseq result result   remain = tail avail 

then break point pattern is:

stopped @ prog1.hs:14:6-23   - recurse stopped @ prog1.hs:15:6-15   - recurse stopped @ prog1.hs:16:18-67  - recurse, call foldr progress stopped @ prog1.hs:21:6-26   - progress, pos = (1,1) stopped @ prog1.hs:14:6-23   - recurse stopped @ prog1.hs:15:6-15 stopped @ prog1.hs:21:6-26   - progress, pos = (1,0) stopped @ prog1.hs:14:6-23   - recurse stopped @ prog1.hs:15:6-15 stopped @ prog1.hs:21:6-26   - progress, pos = (0,1) stopped @ prog1.hs:14:6-23   - recurse stopped @ prog1.hs:15:6-15 stopped @ prog1.hs:21:6-26   - progress, pos = (0,0) stopped @ prog1.hs:14:6-23   - recurse stopped @ prog1.hs:15:6-15 

the recursive calls recurse interleaved because forcing them right away.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -