[Haskell-beginners] hClose: illegal operation (handle is finalized) and/or <<loop>>

Travis Erdman traviserdman at yahoo.com
Tue Aug 17 19:39:26 EDT 2010

> > putStrLn $ show result
> >
> > <<loop>>
> That is the *real* error message.
> It means that where you define result, you refer to result
> also on the right-hand side in a way that is an endless
> loop instead of well-behaved recursion.
> We would have to see more of your code to be able to
> say much more.

Thank you very much ... now I have isolated the offending "loop" code:

I am folding with a function that takes a tree and the input data, and delivers a "processed"/"updated" tree.  The function that is used in the fold is "calcTree".  calcTree is also recursive ... it updates the root node, then recursively calls itself to update each of its children, which is all working fine.  Here are simplified versions of my structure:

data Tree a = Node a [Tree a]

calcTree (Node oldData oldsubtree) input = Node newData recurseChildren
       {-calculate newData from oldData and input-}
       recurseChildren = if {BOOLEANS} then oldsubtree else map (\old -> calcTree old input) oldsubtree

And, in words:  if certain conditions become true, there will be no change in any decedent node from the current node (ie all newData = oldData, and tree structure never changes), so rather than waste exponential time traversing all the decedent nodes, I'd like to just re-use the ones I already have, as they are identical.  This is "pruning" the tree.  If I remove this pruning, the "<<LOOP>>" objection ceases and the code executes as expected ... except it takes lots longer than it should, because there are usually lots of oppt'ys for pruning, and I'd rather not explicitly traverse all of them.

How can I make this work?

Thanks again for all the A's to my Q's !


More information about the Beginners mailing list