
On Sat, Dec 24, 2011 at 11:35 AM, Andy
I have been trying to simulate "Russian peasant multiplication" in Haskell , but I can't produce a list of tuples after I enter 2 integers. I have tried constructing many accumulator functions to do so, but keep getting IO errors.
Why IO errors ? The algorithms is clearly pure, you should write it as an independent function, probably : main1 = do putStrLn "Russian Peasant Multiplication \n" putStrLn "Enter 2 integers : " a <- getInt b <- getInt print (russianMul a b) Or if you want to have the intermediate list : main1 = do putStrLn "Russian Peasant Multiplication \n" putStrLn "Enter 2 integers : " a <- getInt b <- getInt let rows = firstStep a b result = secondStep rows print rows print result russianMul = secondStep . firstStep firstStep a b = .... -- Jedaï