On Tue, Mar 20, 2012 at 5:30 PM, Heinrich Apfelmus <apfelmus@quantentunnel.de> wrote:
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.
Yes, definitely foldl' is worth a try, too:
main = putStrLn $ show $ maxTree $ foldl' (flip insert) Empty toInsert
L.