[Haskell-beginners] Arrays in Haskell

Lorenzo Isella lorenzo.isella at gmail.com
Sat Sep 11 10:09:09 EDT 2010

Dear All,
The recent feedback I got on the mailing list led me to think about the 
data structure I need for my computations and array manipulations 
(loosely speaking, let us say that I need indexing and slicing tables of 
Coming from Python, I am a bit confused: let me say that in my Python 
scripts I almost never use lists, but rather NumPy arrays.
In that case, it is an easy choice (almost every decent software for 
numerics/visualization etc... in Python relies explicitly or implicitly 
on NumPy). On top of that, NumPy is fast, has a lot of inbuilt functions 
and interfaces nicely with SciPy, matplotlib, Mayavi2 etc...
It seems to me (please correct me if I am mistaken) that the situation 
in Haskell is a bit more 'open' to choices.
At least I think so when I look at


I may want to drop lists at some point for performance reasons but also 
because in my work I really have tables of numbers I find convenient to 
think of as arrays/matrices (again, loosely speaking, I mean matrices as 
arrays + linear algebra like taking the inverse, the determinant and so on).
Bottom line, I would need a data type that
(1) is decently fast (OK, there is more than performance to scripting, 
but you see my point)
(2) allows slicing/indexing (e.g. take 3rd row, second column, flatten 
it out, take every element larger than 34 in a row, find its unique 
elements, sort them etc...) without having to re-invent the wheel 
myself. This is more on the manipulation side than the linear algebra. 
As you can see, I would like to be able to find something similar to the 
very useful functions in Data.List for an array.
(3) it would be nice if these data type could have either integers of 
real numbers as entries. If the original data is a made up of integer 
numbers, conversion to real number is always suspicious (I have horrible 
memories (at least in other languages) of numbers that were equal as 
integers and no longer when read as real numbers because of one last 
digit changing...which can give you a headache in some cases.
(4) again it would be nice if I could feed these arrays/vectors to tools 
that take integrals, derivatives, inverse etc...

I am considering for this reason several possibilities


hmatrix is probably what I am looking for (linear algebra, interface to 
gnuplot for plotting, ODE solver etc...) but there is no possibility of 
using arrays of integers, so I am concerned about using it to read and 
compare data files filled with integers where I check if certain entries 
are equal or not. Also I wonder if I can find any extra documentation 
other than the well written tutorial (which explains a lot, but cannot 
do everything in less than 30 pages and I would have plenty of questions 
about array manipulations there).

Any suggestion/clarification is more than welcome.


More information about the Beginners mailing list