On Jan 7, 2006, at 11:56 AM, Chris Kuklewicz wrote:

This is all about lazy evaluation.

Actually, I understand about lazy evaluation. What I don't understand is the extent of variable bindings.

If I desugar the code this far:

main = do n <- getArgs >>= return . read . head
                  main' n

main' n = let p = permutations [1..n]
                        in do mapM_ (putStrLn . concatMap show) $ take 30 p
                                  putStr $ "Pfannkuchen(" ++ show n ++ ") = "
                                  putStrLn . show $ foldl' (flip (max . steps 
0)) 0 p


'p' is a variable bound by a normal 'let.' Why isn't 'p' kept around until the whole 'in' expression is evaluated? If it were, then I assume the GC would be obliged to copy everything it pointed to. In the original version, the author called 'permutations' twice and didn't create a variable binding.

Cheers, David

--------------------------------
David F. Place
mailto:[EMAIL PROTECTED]

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to