[Haskell-beginners] Help on first program

John M. Dlugosz ngnr63q02 at sneakemail.com
Fri Mar 28 23:10:20 UTC 2014


OK, I'm really stuck now.  This gives "out of memory" and doesn't print anything other 
than the first line of output.

	== source code ==
module Main (
     main
) where

solve n src dest tmp =
     do solve (n-1) src tmp dest
        solve 1 src dest tmp
        solve (n-1) tmp dest src

solve 1 src dest _ =
     putStrLn ("move a disk from " ++ src ++ " to " ++ dest)


main = do
     putStrLn "Towers of Hanoi problem"
     solve 5 "A" "B" "C"
	== end ==

Each recursive call is either 1 or (n-1) so it should count down 5,4,3,2,1 and stop the 
recursion.

What am I missing?



More information about the Beginners mailing list