Explicit function call
Wed, 12 Mar 2003 14:27:14 +0000
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]
do a <- myFunc ...
Glynn Clements <email@example.com>