1

I'm trying to get the row of a Data.Array in haskell and also get the column of an array in the form of a tuple or list.
I have something like this:

 array ((0,0),(2,2)) [((i,j),3*i+j)| i <- [0..2], j <- [0..2]]

And I want to get something like:
(0,1,2)
(3,4,5)


or:
(0,3,6)
(1,4,7)

4

2 回答 2

1

您可以使用列表理解: [arr ! (i, 0) | i <- [0..2]]或类似的东西

于 2013-11-01T09:51:02.190 回答
1

你想要的Data.Array.assocs功能:

Prelude> import Data.Array
Prelude Data.Array> let arr = array ((0,0),(2,2)) [((i,j),3*i+j)
                                                  | i <- [0..2], j <- [0..2]]
Prelude Data.Array> assocs arr
[((0,0),0),((0,1),1),((0,2),2),((1,0),3)
,((1,1),4),((1,2),5),((2,0),6),((2,1),7),((2,2),8)]
于 2013-11-01T03:29:11.940 回答