<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:10pt;font-family:Monospace">
<p>Henning:</p>
<p></p>
<p><span style="color:#008000">>I was wrong, the different names are synonymes for the same type. :-(</span></p>
<p></p>
<p>I agree that we must statically distinguish Vector and Matrix (see below).</p>
<p></p>
<p><span style="color:#008000">> Some notes: I would not call it a matrix library but a linear algebra</span></p>
<p><span style="color:#008000">> library. Then setup modules like LinearAlgebra.Matrix,</span></p>
<p><span style="color:#008000">> LinearAlgebra.Vector and so on and move functions related to each type</span></p>
<p><span style="color:#008000">> into these modules. Vector is more basic than Matrix, thus Matrix should</span></p>
<p><span style="color:#008000">> import Vector, not vice versa, it should contain Matrix-Vector operations.</span></p>
<p><span style="color:#008000">> The Vector module could contain e.g. the scalar product. I also find it</span></p>
<p><span style="color:#008000">> good style not to repeat the modules name in function and type names. E.g.</span></p>
<p><span style="color:#008000">> Matrix.mulVector is a good function name, but the type name should also</span></p>
<p><span style="color:#008000">> not be Matrix.Matrix but say Matrix.T. Unfortunately this style is not</span></p>
<p><span style="color:#008000">> very widely spread currently, I wished it would be more. </span></p>
<p></p>
<p>You are right, module structure and names are provisional.</p>
<p></p>
<p><span style="color:#008000">> Then you may </span></p>
<p><span style="color:#008000">> consider no to restrict the library to Double. Most operations can be</span></p>
<p><span style="color:#008000">> defined in terms of any numbers (including even say matrices of matrices).</span></p>
<p><span style="color:#008000">> This can be handled by type classes. The instances for Double can invoke</span></p>
<p><span style="color:#008000">> GSL, others may use Haskell routines.</span></p>
<p></p>
<p>Ok. Currently we can have "blocks" of Storable types. Block Double works with </p>
<p>the GSL and Block Int is only in Num, using Haskell. Clearly we should admit </p>
<p>other any number as base type. </p>
<p></p>
<p><span style="color:#008000">> If you are interested I have here some algorithm for computing the</span></p>
<p><span style="color:#008000">> determinant of a n by n matrix in n^4 steps which does not need division</span></p>
<p><span style="color:#008000">> and thus can be used for integers and polynomials.</span></p>
<p></p>
<p>Of course I would like to see it, and we can include it in the library...</p>
<p></p>
<p></p>
<p>David: </p>
<p></p>
<p><span style="color:#008000">> The one thing I'd like to see (and here I agree with Hennig) is a</span></p>
<p><span style="color:#008000">> distinction between matrices and tensors. Your library is really very</span></p>
<p><span style="color:#008000">> tensor-based, but tensors and matrices are very different beasts.</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">> I imagine one could take your Block, which is really a sort of generalized</span></p>
<p><span style="color:#008000">> tensor, and implement a Matrix type such as</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">> data Matrix = M (Block Double)</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">> (or perhaps for arbitrary element type) with the constructor not exported,</span></p>
<p><span style="color:#008000">> so that Matrices will always be guaranteed to be two-dimensional.</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">> Then for matrices one could define * to be matrix multiplication, sqrt,</span></p>
<p><span style="color:#008000">> exp, cos, sin etc to be matrix functions (expm etc in octave-speak), and</span></p>
<p><span style="color:#008000">> then define .* and ./ to be as defined in octave.</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">> This definition would allow considerably more type-safeness than your</span></p>
<p><span style="color:#008000">> current implementation (which seems scarily dynamically typed to me).</span></p>
<p></p>
<p>To me too! Due to the type trickery required to statically check matrix </p>
<p>dimensions in this first version I also used a common type for blocks with </p>
<p>any number of indices, which ruins many of the Haskell advantages.</p>
<p></p>
<p>I will work on your idea. We can have different types for scalar, vector and </p>
<p>matrix, with elementwise numeric operations, and using multiparamenter </p>
<p>classes we can statically check typical multiplications and other functions. </p>
<p>We can also define a constructor from vectors or matrices to arbitrary </p>
<p>blocks, to be used (dynamically) in more general but less frequent </p>
<p>situations. </p>
<p></p>
<p><span style="color:#008000">> Alas, we'd still not have the truly strong typing I'd dream about where one</span></p>
<p><span style="color:#008000">> could define</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">> matMul :: Int n, m, l => Matrix n m -> Matrix m l -> Matrix n l</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">> which as I understand things, isn't possible in Haskell without some sort</span></p>
<p><span style="color:#008000">> of weird type trickery. Of course, if you had this kind of type trickery,</span></p>
<p><span style="color:#008000">> you might not need to declare a separate Matrix type, since you'd be able</span></p>
<p><span style="color:#008000">> to represent the dimensionality of the Block in its type.</span></p>
<p><span style="color:#008000">></span></p>
<p><span style="color:#008000">> And hopefully you and he can work together to create a great library (and</span></p>
<p><span style="color:#008000">> I'll be able to mooch off of whatever you create...). :)</span></p>
<p></p>
<p>Of course! I am very happy to know that other people is also interested in a </p>
<p>simple "scientific computing" library for Haskell.</p>
<p></p>
<p>Alberto</p>
<p></p>
</body></html>