Nate Faubion on Array building:
In my experience, using unsafe
ST
is not necessary … I switched to building a reversedList
, then usingArray.fromUnfoldable
andArray.reverse
. Both of those array operations are extremely cheap.Array.fromUnfoldable
specifically builds an array with mutation and does not need to copy the final result.Array.reverse
is much cheaper thanList.reverse
.
ST
still has to allocate effect closures and binds at each step, which will be equivalent to allocatingCons
cells.
I’ve tried this advice in a few places and it’s always easier to program and slightly faster at runtime. Instead of building an Array
with Data.Array.ST.push
, build up a reversed rlist :: List
with cons
and then
Array.reverse $ Array.fromFoldable rlist