[Haskell-cafe] Expanding do notation
bertram.felgenhauer at googlemail.com
Mon Jan 9 04:56:16 EST 2006
David F. Place wrote:
> 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
> In the original version, the author called 'permutations' twice and
> didn't create a variable binding.
As a side note, I expected GHC to do common subexpression elimination and
evaluate permutations [1..n] only once, caching the 30 results that are
used twice. I didn't try to find out whether it actually did though.
More information about the Haskell-Cafe