[Haskell-cafe] Bad recursion? When can something be on both sides of an equation?
jeffbrown.the at gmail.com
Thu Mar 12 07:49:57 UTC 2015
In another thread , I talked about computing what I've been lately
calling the "total descendents" of a subset S of a graph: that is, the set
of nodes t for which every maximal sequence of predecessors intersects S. I
got it done, functionally . But in the process I wrote something that
hangs, and I can't figure out why.
The problem arose in the following passage. (Glab stands for Graph Label, a
synonym for Int.)
totalDescendents :: S.Set Glab -> Graph -> S.Set Glab
totalDescendents roots graph = b
where (a,b,c,graph) = totalDescendentsCtrlr -- tricky
(roots, S.empty, M.empty, graph)
totalDescendentsCtrlr :: TotalDescendentsData -> TotalDescendentsData
totalDescendentsCtrlr (a,b,c,gr) =
if S.null a' -- fails, as does a == a'
-- a == a' is one iteration slower but should have same effect
else totalDescendentsCtrlr (a',b',c',gr')
where (a',b',c',gr') = visitUndetPrds $ visitTdSnvSucs (a,b,c,gr)
Notice that in the equation marked "tricky", the object "graph" appears on
both sides. I thought that was the problem, so I rewrote that line as the
where (_,b,_,_) = totalDescendentsCtrlr
and sure enough, the problem vanished.
So I tried to distill that problem to something tiny, and came up with this:
f (a) = a'
where (a',b) = fBackend (a,b) -- tricky
fBackend (a,b) =
if a' < 1
else fBackend (a',b)
where a' = a - 1
I see no substantive difference between the problem with the first body of
code and the problem I expected f and fBackend to have -- but f and
fBackend work fine!
Any idea what might be happening?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe