Nate Faubion on Array building:
In my experience, using unsafe
STis not necessary … I switched to building a reversedList, then usingArray.fromUnfoldableandArray.reverse. Both of those array operations are extremely cheap.Array.fromUnfoldablespecifically builds an array with mutation and does not need to copy the final result.Array.reverseis much cheaper thanList.reverse.
STstill has to allocate effect closures and binds at each step, which will be equivalent to allocatingConscells.
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