[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-beginners
Subject:    Re: [Haskell-beginners] construct list
From:       Chaddaï Fouché <chaddai.fouche () gmail ! com>
Date:       2011-12-24 11:14:34
Message-ID: CANfjZRZ3_6e68xvgB9nSJVYom+v3NSz5URtOHdkdxj7a67N7qw () mail ! gmail ! com
[Download RAW message or body]

On Sat, Dec 24, 2011 at 11:35 AM, Andy <ablaroc@gmail.com> wrote:
> 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ï

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic