How unsafe are unsafeThawArray# and unsafeFreezeArray#

Johan Tibell johan.tibell at
Fri Mar 9 20:51:49 CET 2012

On Fri, Mar 9, 2012 at 11:39 AM, Twan van Laarhoven <twanvl at> wrote:
> Quick follow up question:
> Are unsafeThawArray# and unsafeFreezeArray# guaranteed to not make a copy?
> I.e. are these two pieces of code equivalent with respect to further usage
> of the return value:
>    do mary <- unsafeThawArray# ary
>       writeArray# mary 123# newValue
>       unsafeFreezeArray# mary
> and
>    do mary <- unsafeThawArray# ary
>       writeArray# mary 123# newValue
>       return ary
> (where do notation is actually done manually.)

I believe you

 * don't have to use the return value from unsafeFreezeArray#, you can
use the (now mutated) Array# initially passed to unsafeThawArray#, but
 * you must call unsafeFreezeArray# to make sure the header of the
heap object is updated correctly.

At least this is what I did in unordered-containers here:


More information about the Glasgow-haskell-users mailing list