Array of arrays to a single nxn dimensional array

Thanks for the pointer. But arguably, the same optimization can be applied to foldl since allocating once seems orthogonal to associativity, I don’t see how they are related.