RE: unsafePerformIO around FFI calls
23 Jul
2002
23 Jul
'02
4:46 p.m.
If this is true, then is it equivalently safe to wrap the following Haskell action in unsafePerformIO:
myFunc i = do arr <- newArray (0,255) 0 mapM_ (\j -> writeArray arr j (i+j)) [0..255] foo <- newIORef 0 mapM_ (\j -> readArray arr j >>= modifyIORef foo (+j)) [0..255] readIORef foo >>= return
? (don't call me on syntax errors -- i haven't checked this at all, but you should get the idea)
Yes, but for this particular case you would use the ST monad instead (with STArray and STRef). That way you get to avoid mentioning anything with 'unsafe' in its name, and the compiler does the safety proof for you. Cheers, Simon
8802
Age (days ago)
8802
Last active (days ago)
0 comments
1 participants
participants (1)
-
Simon Marlow