I’m playing with Haskell and Project Euler’s 23rd problem. After solving it with lists I went here where I saw some array work. This solution was much faster than mine.
So here’s the question. When should I use arrays in Haskell? Is their performance better than lists’ and in which cases?
I’m playing with Haskell and Project Euler’s 23rd problem. After solving it with lists
Share
And if you’re doing much indexing as well as much updating,you can
Maps (orIntMaps), O(log size) indexing and update, good enough for most uses, code easy to get rightMaps are too slow, use mutable (unboxed) arrays (STUArrayfromData.Array.STor STVectors from the vector package; O(1) indexing and update, but the code is easier to get wrong and generally not as nice.For specific uses, functions like
accumArraygive very good performance too (uses mutable arrays under the hood).