I can see that it's possible to write functions like map/sortBy/findIndex and some other List-related functions for Arrays instead (at least those indexed by integers.) Is this done anywhere in the standard library, or would I need to roll my own?
I need to use an array in my program for the in-place update, but there are also several locations I'd like to use some of the above list functions on it. Is converting back and forth between the two the best solution?
(The arrays I've been looking at are from Data.Array.IArray. I'm also happy to use any other array library that implements this functionality.)
I recommend you have a look at the vector and vector-algorithms packages. They contain very efficient implementations of many common operations on Int
-indexed arrays, in both mutable and immutable variants.
fmap
(from Control.Monad
) is sort of like a generic version of map
that works on anything that supports the Functor
type class. Array
supports that, so you should be able to use fmap
instead of map
for array.
As hammar says, the vector and vector-algorithms are probably a better way to approach the problem if you need to consider indexed arrays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With