[Haskell-cafe] unsafeThawByteArray#

Patrick Perry patperry at stanford.edu
Thu Dec 11 16:54:52 EST 2008


I've noticed that there is no longer an "unsafeThawByteArray#"  
function in GHC.Prim.
Looking through the darcs history, I found a patch with description:

[project @ 2000-03-13 12:11:43 by simonmar]
simonmar**20000313121144
  Remove unsafeThawByteArray# primop (which was a no-op), and use
  unsafeCoerce# instead.
]

Is the following code safe?

data IntArray     = IntArray   !Int (ByteArray#)
data STIntArray s = STIntArray !Int (MutableByteArray# s)

unsafeThaw :: IntArray -> ST s (STIntArray s)
unsafeThaw (IntArray n arr#) =
     ST $ \s1# ->
         let coerceArray :: State# s -> MutableByteArray# s
             coerceArray _ = unsafeCoerce# arr#
             marr# = coerceArray s1#
             marr  = STIntArray n marr# in
         (# s1#, marr #)

Thanks,


Patrick



More information about the Haskell-Cafe mailing list