Regular, shape-polymorphic, parallel arrays in Haskell
The paper Regular, shape-polymorphic, parallel arrays in Haskell describes a new Haskell library, named Repa, for multi-dimensional, regular arrays based on our work on Data Parallel Haskell and a delayed array representation avoiding unnecessary data structures. As the following table shows, the sequential performance already gets close to the performance of C programs. More importantly, the Haskell code transparently makes use of multicore hardware — something that is much more difficult in C.
The Haskell code is purely functional, using collective array operations. Here is matrix-matrix multiplication:
mmMult :: (Num e, Elt e)
=> Array DIM2 e -> Array DIM2 e -> Array DIM2 e
mmMult arr brr = sum (zipWith (*) arrRepl brrRepl)
where
trr = force (transpose2D brr)
arrRepl = replicate (Z :.All :.colsB :.All) arr
brrRepl = replicate (Z :.All :.All :.rowsA) trr
(Z:. colsA:. rowsA) = extent arr
(Z:. colsB:. rowsB) = extent brr
In addition to good performance, the library facilitates reuse through the use of shape polymorphism.