Explicit function call

2003-03-12 Thread Pavel G. Zhbanov
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
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Explicit function call

2003-03-12 Thread Jon Cast
[EMAIL PROTECTED] (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

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Explicit function call

2003-03-12 Thread Glynn Clements

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 [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe