Can't make sense of newArray# docs

Johan Tibell johan.tibell at
Tue Jan 18 23:18:33 CET 2011


The docs for newArray# states:

"Create a new mutable array of specified size (in bytes), in the
specified state thread, with each element containing the specified
initial value."

Why is the size in bytes? Is Array# meant to be used both for boxed
and unboxed values? For arrays of boxed values I'd expect the size to
be the number of elements and the allocated size the number of
elements multiplied by the size of a pointer. Are the docs correct? If
so, how do I allocate an Array# of pointers? I'm trying to implement
the following array type:

    data MurableArray s a = Array { unArray :: !(MutableArray# s a) }

i.e. an array of boxed values. I can't figure out how to write

    new :: Int -> a -> ST s (MutableArray s a)

where the first argument is the number of elements (of type a).


More information about the Glasgow-haskell-users mailing list