[Haskell-cafe] Re: [Haskell] ANNOUNCE: An index-aware linear algebra library in Haskell

Alberto Ruiz aruiz at um.es
Sun Apr 16 11:06:55 EDT 2006

It is really counterintuitive! I will study carefully your library and the 
"Implicit Configurations" paper. Using static dimension checking we can write 
very solid code for matrix computations...

However, I don't know how to write some definitions. For instance, this is ok:

m = $(dAM [[1,2,3]])

but with:

x = [[1,2,3]] :: [[Double]]
m1 = $(dAM x)
m2 = listMat x

main = do
    print m1
    print m2

I get:

    GHC stage restriction: `x'
      is used in a top-level splice, and must be imported, not defined locally
    In the first argument of `dAM', namely `x'
    In the definition of `m1': m1 = $[splice](dAM x)

    Inferred type is less polymorphic than expected
      Quantified type variable `m' escapes
      Quantified type variable `n' escapes
      Expected type: (v (L m, L n) -> w) -> t
      Inferred type: (forall n1 m1.
                      (ReflectNum n1, ReflectNum m1) =>
                      v (L m1, L n1) -> w)
                     -> w
    In the first argument of `print', namely `m2'
    In the result of a 'do' expression: print m2

I would also like to create a matrix from a data file:

main = do
    let m1 = $(dAM [[1,2],[3,4::Double]])
    s <- readFile "data.txt"
    let list = read s :: [[Double]]
    --let m2 = $(dAM list)
    let m2 = listMat list
    print $ m2 *> trans m1

But I get a similar error. Perhaps I must provide information about the 
expected dimensions, but I don't know how to do it.


On Saturday 15 April 2006 22:09, Frederik Eaton wrote:
> Yes, certainly... Otherwise the library would not be much use! If it
> seems counterintuitive, as it did to me at first, you should check out
> the "Implicit Configurations" paper, which uses modular arithmetic as
> an example. My version of their code is in
> http://ofb.net/~frederik/futility/src/Prepose.hs
> The function I mainly use is:
> reifyIntegral :: Integral a => a -> (forall s. ReflectNum s => s -> w) -> w
> which turns an integral value into a type of the ReflectNum class
> which represents that value, and calls the provided polymorphic
> function with a dummy value (actually 'undefined') of that type; then
> returning the function's result.
> Frederik
> On Sat, Apr 15, 2006 at 06:14:44PM +0200, Alberto Ruiz wrote:
> > On Friday 14 April 2006 17:02, Frederik Eaton wrote:
> > > An index-aware linear algebra library in Haskell
> >
> > Excellent work!
> >
> > Is it possible to create a vector or matrix whose size is not known at
> > compile time?
> >

More information about the Haskell-Cafe mailing list