
Hello, How can I make an explicit function call in a "do" sequence? Ex: ... do let a = myFunc ... b = myFunc ... c = "Something else" return c ... As I understand myFunc will not be executed, but I need it... Please, help. -- Pavel Zhbanov

How can I make an explicit function call in a "do" sequence?
Ex: ... do let a = myFunc ... b = myFunc ... c = "Something else" return c ...
As I understand myFunc will not be executed,
Correct.
but I need it...
If it has a side effect, it will have type "IO something" (or whatever monad your using) and you can write: do a <- myFunc ... If it doesn't have a side effect, why do it anyway? The result 'c' does not depend on a. Arjan

pavel@joker.botik.ru (Pavel G. Zhbanov) wrote:
If it doesn't have a side effect, why do it anyway? The result 'c' does not depend on a.
myFunc uses IORef and it's (IORef's) result I use afterwards in some other functions.
OK: what is myFunc's type? If it ends in IO alpha, for some alpha, you can say: do a <- myFunc ... etc. If it doesn't, then you should probably re-think its definition. Jon Cast

On Wed, Mar 12, 2003 at 07:52:52AM -0600, Jon Cast wrote:
pavel@joker.botik.ru (Pavel G. Zhbanov) wrote:
If it doesn't have a side effect, why do it anyway? The result 'c' does not depend on a.
myFunc uses IORef and it's (IORef's) result I use afterwards in some other functions.
OK: what is myFunc's type? If it ends in IO alpha, for some alpha, you can say: do a <- myFunc ... etc. If it doesn't, then you should probably re-think its definition.
Jon Cast
myFunc :: a -> [b] (a and b are my own types) Actually, inside myFunc I used unsafePerformIO (didn't want to change the whole programm just because of one function). The purpose of myFunc is to append some value to "some list" lying somewhere (somewhere is "defined" by IORef), store the resulting list and return a copy. I want to do something like this (in a sequence): append two values to "some list" , then call a function (myFunc2) that uses "some list" and return the value returned by myFunc2. -- Pavel Zhbanov

Pavel G. Zhbanov wrote:
If it doesn't have a side effect, why do it anyway? The result 'c' does not depend on a.
myFunc uses IORef and it's (IORef's) result I use afterwards in some other functions.
OK: what is myFunc's type? If it ends in IO alpha, for some alpha, you can say: do a <- myFunc ... etc. If it doesn't, then you should probably re-think its definition.
myFunc :: a -> [b] (a and b are my own types)
Actually, inside myFunc I used unsafePerformIO (didn't want to change the whole programm just because of one function). The purpose of myFunc is to append some value to "some list" lying somewhere (somewhere is "defined" by IORef), store the resulting list and return a copy.
There's a reason why the name unsafePerformIO begins with "unsafe". It
is *not* a magic wand that can simply get rid of the "IO" whenever it
turns out to be inconvenient.
You need to change myFunc's type to:
myFunc :: a -> IO [b]
then use:
do a <- myFunc ...
--
Glynn Clements
participants (4)
-
Arjan van IJzendoorn
-
Glynn Clements
-
Jon Cast
-
pavel@joker.botik.ru