[Haskell-cafe] Numerical Analysis

Roman Leshchinskiy rl at cse.unsw.edu.au
Mon May 17 23:14:45 EDT 2010


On 17/05/2010, at 02:52, Pierre-Etienne Meunier wrote:

>> You are quite right that vector only supports nested arrays but not multidimensional ones. This is by design, however - the library's only goal is to provide efficient one-dimensional, Int-indexed arrays. I'm thinking about how to implement multidimensional arrays on top of vector but it's not that easy. While repa is a step in that direction, I also need to support mutable arrays and interoperability with C which complicates things immensely.
> 
> I understand. What complicates it even more (at least in what I imagine) is that C uses the same syntax for multidimensional and nested arrays, and I do not believe that for instance GHC's FFI allows for array types such as "int x[19][3]".

Actually, it does since an argument of that type is equivalent to int *x. FWIW, I always say "nested array" when I mean that the individual subarrays can have different lengths as opposed to multidimensional ones where they are all the same. So the former are similar to int *x[].

> I was also wondering about how to do linear algebra : an infinite number of types would be needed to express all the constraints on matrix multiplication : we need types such as "array of size m * n". Is there a way to generate these automatically with for instance template haskell (again ! But I know nothing of template haskell, neither, sorry !)

Encoding the bounds in the type system is possible but rather messy. In general, simply saying the array has indices of type (Int,Int) and doing dynamic bounds check when necessary seems to work best in Haskell.

Roman




More information about the Haskell-Cafe mailing list