[Haskell-beginners] Red-black tree performance

Lorenzo Bolla lbolla at gmail.com
Tue Mar 20 22:03:30 CET 2012


On Tue, Mar 20, 2012 at 5:30 PM, Heinrich Apfelmus <
apfelmus at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120320/53b8c3df/attachment-0001.htm>


More information about the Beginners mailing list