On 2/2/06, MaurĂ­cio <[EMAIL PROTECTED]> wrote:
>    I understand those examples, but I really would like to know how to
> do that with monads. I would like to ask the same question, but now with
> this code:
>
> double a = 1000;
> double b = 0;
> while (a != b) {
>      a /= 2;
>      cout << a; // Prints a
>      cin << b; // User gives a number, stored in b
> };

An idiomatic approach:
example :: Double -> Double -> IO ()
example a b
    | a == b    = return ()
    | otherwise = do
        let a' = a / 2
        print a'
        b' <- readLn
        example a' b'

main = example 1000 0
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to