
20 Mar
2012
20 Mar
'12
1:30 p.m.
Lorenzo Bolla wrote:
Your scripts stack-overflows on my box.
I've made 2 little changes, to ensure strictness. I believe your "insertList" is building up a huge list of thunks.
import Data.Foldable (foldr') <snip> main :: IO () main = putStrLn $ show $ maxTree $ foldr' insert Empty toInsert
Better?
Huh, why foldr' and not Data.List.foldl' ? As far as I understand, the former has to evaluate the whole spine of the list first before it can begin to assemble the tree. The latter can start building trees right away. I'm not sure whether the integers in toInsert are evaluated to WHNF. You can make the insert function strict in the first argument to make sure that they are. Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com