[Haskell-cafe] Sequencing Operations in a Monad

Paul Johnson paul at cogito.org.uk
Sat Sep 15 05:28:07 EDT 2007

SevenThunders wrote:
> Unfortunately if I wrap my  matrix references in the IO monad, then at best
> computations like 
> S = A + B are themselves IO computations and thus whenever they are
> 'invoked' the computation ends up getting performed repeatedly contrary to
> my intentions.  
This sounds like a case for the infamous performUnsafeIO.  The reason 
this is "unsafe" is that the compiler assumes that the IO computation it 
wraps has no visible side effects, so it doesn't matter when it is 
performed or how many times it gets performed.  If your IO computation 
indeed has this nature then you are OK, but its up to you to make sure 
of this.


More information about the Haskell-Cafe mailing list