[Haskell-cafe] Simple matrix
jupdike at gmail.com
Wed Jun 21 17:27:44 EDT 2006
> I dont see how to fix this.
There was a thread about statically knowing lots about the shape of
matrices using the type system.
I believe they incorporated this (variable size identity matrix, for
example) in their approach. (They don't preserve your property of
being able to do things with simple list syntax, like [[1,2],[3,4]] *
[[5,6],[7,8]] , instead you have to use Template Haskell and some
small contructor functions)
> Could be better to forget about fromInteger...
Except then you wouldn't have a full instance for Num. How about
constructing an infite list of infinite lists of that number:
fromInteger x = map repeat (repeat (fromInteger x))
when it gets zipped with smaller matrices, will it terminate?
It works with addition but multiplying caused problems:
[[1,2],[3,4]] + 10 = [[11,12],[13,14]]
[[1,2],[3,4]] * 10 = [[40,60],[40,60],[40,60],[40,60],[40,60], .....
> Jared Updike wrote:
> >> fromInteger x = [[fromInteger x]]
> > Wouldn't you want the expression
> > [[1,0],[0,2]] + 10
> > to yield
> > [[11,10],[10,12]]
> > instead of [] ? I guess you would need some complicated machinery
> > so this is one thing you have to ignore to keep your otherwise nifty
> > instance nice and simple.
> > Jared.
More information about the Haskell-Cafe