[Haskell-cafe] Re: Haskell code for this example of flow control

2006-02-04 Thread Dominic Steinitz
Here are some even older discussions on the subject. I don't know if anyone ever put them into a library or on the wiki. Dominic. http://haskell.org/pipermail/haskell-cafe/2005-May/009784.html http://www.haskell.org//pipermail/libraries/2005-February/003143.html ___

Re: [Haskell-cafe] Re: Haskell code for this example of flow control

2006-02-04 Thread Bulat Ziganshin
Hello Maurício, Friday, February 03, 2006, 7:28:16 PM, you wrote: M>I wonder if I could write a generic while based on your example: while :: (a ->> IO a) -> (a -> Bool) -> IO () M>I'll probably learn something trying that. i have about 5-10 imperative control structures defined in my

Re: [Haskell-cafe] Re: Haskell code for this example of flow control

2006-02-03 Thread Robert Dockins
On Feb 3, 2006, at 11:28 AM, Maurício wrote: Kurt Hutchinson wrote: 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; dou

[Haskell-cafe] Re: Haskell code for this example of flow control

2006-02-03 Thread Maurício
Kurt Hutchinson wrote: 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 <

Re: [Haskell-cafe] Re: Haskell code for this example of flow control

2006-02-02 Thread Kurt Hutchinson
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; //

Re: [Haskell-cafe] Re: Haskell code for this example of flow control

2006-02-02 Thread Chris Kuklewicz
Maurício 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; // Use

Re: [Haskell-cafe] Re: Haskell code for this example of flow control

2006-02-02 Thread Robert Dockins
I think you're looking for IORef http://www.haskell.org/ghc/docs/ latest/html/libraries/base/Data-IORef.html Something like this (untested) should do what you want: example :: IO () example = do { ref <- newIORef 1000; loop ref } where loop ref = do x <- readIORef ref print x

[Haskell-cafe] Re: Haskell code for this example of flow control

2006-02-02 Thread Maurício
Donald Bruce Stewart wrote: briqueabraque: Hi, I would like to know what options I have in Haskell to do something similar to this C++ code: double a = 1000; while (a>1) a/=2; I'm able to do that with lists, but I would like to know how to do that with monads and variables with state.