Iterating arrays in haskell

My problem is that I need to iterate over the array and calculate some kind of value depending on each element. I was looking for some bend type function for arrays, but the standard library seems very useless with arrays. Or am I missing something?

Another solution could be an array of list bindings. Binding means that I do not want to copy this array. Is it possible?

Btw, all about a simple array.

+4
source share
4 answers

Somehow I happened to survive this article the other day: Folding arrays

+9
source

Take a look at Data.Foldable . It defines a type class that does exactly what you want.

+8
source

Using Data.Foldable , you can foldr / foldl a Array just like a list.

Another option is that you can convert Array back to a list using elems and then foldr or foldl through the list.

+2
source

What type of array are you using? Perhaps you can just collapse over the index.

Or use one of the array libraries that directly support bends (uvector).

+1
source

All Articles