How to represent a numerical table (for example a contingency table) in Haskell?

187 views Asked by At

In C the easiest way would be using a bi-dimensional array. What about Haskell? A list of lists does not seem an elegant solution. What would you suggest?

2

There are 2 answers

0
Bartek Banachewicz On

Haskell has extensive collection of Arrays, Vectors, and other containers.

To choose between one of them, you need to know your requirements in a bit more detail.

5
Don Stewart On

Multi-dimensional array literals can be described using list syntax but with whichever underlying data type you feel is most appropriate. E.g.

x :: Array U DIM3 Int
x = fromListUnboxed (Z :. (3::Int) :. (3::Int) :. (3::Int))
           [1,2,3
           ,4,5,6
           ,7,8,9

           ,10,11,12
           ,13,14,15
           ,16,17,18

           ,19,20,21
           ,22,23,24
           ,25,26,27]

Is a 3 dimensional array (type DIM3 Int). The concrete syntax can be given in list notation (either flat or nested), and the compiler will take care of the object construction.