News for hackers. Stuff that matters.
Re:Once you go functional, you can never go back by sriku on Thursday May 21, 2015 @12:22AM (#9580938)
> Edit: Actually, the Haskell version can be O(1) in memory as the front of the list can be garbage collected, while the C++ version is O(n) in memory.

Do you expect the following code to run in constant space?

    head (drop 1000000000 (let fibs = 0 : 1 : zipWith max fibs (tail fibs) in fibs))
Neither ghci nor ghc seems to run it in constant space.
Re:Once you go functional, you can never go back by tome on Thursday May 21, 2015 @02:25AM (#9581231)
That's because the entries in fibs are thunks which become very large. This runs in constant space:

    zipWith' f (x:xs) (y:ys) = let r = f x y in r `seq` r : zipWith' f xs ys
    head (drop (10 ^ 9) (let fibs = 0 : 1 : zipWith max fibs (tail fibs) in fibs))
Re:Once you go functional, you can never go back by sriku on Saturday May 23, 2015 @04:31AM (#9592342)
Nice. .. and you meant to type zipWith' on the second line.
Re:Once you go functional, you can never go back by tome on Saturday May 23, 2015 @09:14AM (#9592811)
Yeah I did!