I am having trouble with the type declaration for creating an identity matrix.

initIdentityMat :: Int -> ST s (STUArray s (Int,Int) ((Int, Int), Double)) initIdentityMat m = newListArray ((1,m),(1,m)) ([((i,j), if i == j then 1.0 else 0.0) | i <- [1..m], j <- [1..m]] :: [((Int,Int), Double)]) Doesn't seem to compile, nor do minor variations of the type declaration. -- -- Regards, KC

Your problem is that you're including the (i, j) in your array element
type, when you really only want it to be in your index type (I assume).
This would not normally be an issue, but an unboxed array doesn't work on
an element type of ((Int, Int), Double).
You might consider instead making a new unboxed array with a default value
of 0.0, and then forM_ an action that writes 1.0 at index (i, i).
On Tue, Apr 24, 2012 at 5:20 PM, KC
initIdentityMat :: Int -> ST s (STUArray s (Int,Int) ((Int, Int), Double)) initIdentityMat m = newListArray ((1,m),(1,m)) ([((i,j), if i == j then 1.0 else 0.0) | i <- [1..m], j <- [1..m]] :: [((Int,Int), Double)])
Doesn't seem to compile, nor do minor variations of the type declaration.
-- -- Regards, KC
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Tue, Apr 24, 2012 at 3:20 PM, KC
initIdentityMat :: Int -> ST s (STUArray s (Int,Int) ((Int, Int), Double)) initIdentityMat m = newListArray ((1,m),(1,m)) ([((i,j), if i == j then 1.0 else 0.0) | i <- [1..m], j <- [1..m]] :: [((Int,Int), Double)])
Doesn't seem to compile, nor do minor variations of the type declaration.
If you use Hoogle to find the type and API docs for 'newListArray', I believe you'll be able to figure out what's wrong, but I'll give you a hint. The list you're giving to 'newListArray' contains too much; and the pair you give it is only half correct. Kevin -- Kevin Charter kevin.charter@acm.org

Thank you.
One is ONLY supposed to supply the list elements for "newListArray" which
fill the array in increasing order.
On Tue, Apr 24, 2012 at 3:21 PM, Kevin Charter
On Tue, Apr 24, 2012 at 3:20 PM, KC
wrote: initIdentityMat :: Int -> ST s (STUArray s (Int,Int) ((Int, Int), Double)) initIdentityMat m = newListArray ((1,m),(1,m)) ([((i,j), if i == j then 1.0 else 0.0) | i <- [1..m], j <- [1..m]] :: [((Int,Int), Double)])
Doesn't seem to compile, nor do minor variations of the type declaration.
If you use Hoogle to find the type and API docs for 'newListArray', I believe you'll be able to figure out what's wrong, but I'll give you a hint. The list you're giving to 'newListArray' contains too much; and the pair you give it is only half correct.
Kevin
-- Kevin Charter kevin.charter@acm.org
-- -- Regards, KC
participants (3)
-
Daniel Peebles
-
KC
-
Kevin Charter