
Folks, Why use runST in the following example at http://www.n-heptane.com/nhlab/repos/NewBinary/Tests/BinDouble.hs ? doubleToInts d = runST ( do arr <- newDoubleArray (1,2) writeDoubleArray arr 1 d i1 <- readIntArray arr 1 i2 <- readIntArray arr 2 return (i1,i2)) Isn't it possible to do the same within the IO monad? Thanks, Joel -- http://wagerlabs.com/idealab

Not if you want a pure result. The IO monad is one-way, whereas ST has
runST to get back a result.
- Cale
On 07/10/05, Joel Reymont
Folks,
Why use runST in the following example at
http://www.n-heptane.com/nhlab/repos/NewBinary/Tests/BinDouble.hs ?
doubleToInts d = runST ( do arr <- newDoubleArray (1,2) writeDoubleArray arr 1 d i1 <- readIntArray arr 1 i2 <- readIntArray arr 2 return (i1,i2))
Isn't it possible to do the same within the IO monad?
Thanks, Joel
-- http://wagerlabs.com/idealab
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 10/8/05, Joel Reymont
Folks,
Why use runST in the following example at
http://www.n-heptane.com/nhlab/repos/NewBinary/Tests/BinDouble.hs ?
doubleToInts d = runST ( do arr <- newDoubleArray (1,2) writeDoubleArray arr 1 d i1 <- readIntArray arr 1 i2 <- readIntArray arr 2 return (i1,i2))
Isn't it possible to do the same within the IO monad?
It is, but why would you want to? doubleToInts in your example could be called from a pure function, whereas an IO-action doing the same could only be called from other IO actions. So, rule of thumb: Don't use IO if you don't really really REALLY need it. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862
participants (3)
-
Cale Gibbard
-
Joel Reymont
-
Sebastian Sylvan