Question about lists

hello there, To be honest I'm not very familiar with haskell and stuff so don't laugh with my question... here it goes.. We can represent a matrix as a list of lists... which means that 1 2 3 4 7 6 2 5 1 could be written as follows: [[1,2,3],[4,7,6],[2,5,1]] The question is how can I reverse the matrix (each row becomes a column) Thanx a lot ______________________________________________________________________________________ http://mobile.pathfinder.gr - Pathfinder Mobile logos & Ringtones! http://www.pathfinder.gr - Δωρεάν mail από τον Pathfinder!

cris cris wrote:
We can represent a matrix as a list of lists... which means that 1 2 3 4 7 6 2 5 1 could be written as follows: [[1,2,3],[4,7,6],[2,5,1]] The question is how can I reverse the matrix (each row becomes a column)
Sounds like homework time again. At the risk of being overly rude my immediate response is that instead of representing a matrix as a list of lists, we should represent it as a structure : data Matrix a = Mtrx Info ((Matrix a) -> [Int] -> a) [a] (That third bit could be [[a]] to match the problem more exactly) where the first part contains information like how big the thing is and the second part is an accessor function. Then to "reverse" the given matrix, we'd only have to change the second part (since its square the Info part would not change). With the given problem, if the accessor function were "af" then the answer would be simply : \m c -> af m (reverse c)

cris cris wrote:
To be honest I'm not very familiar with haskell and stuff so don't laugh with my question... here it goes.. We can represent a matrix as a list of lists... which means that 1 2 3 4 7 6 2 5 1 could be written as follows: [[1,2,3],[4,7,6],[2,5,1]] The question is how can I reverse the matrix (each row becomes a column)
The "transpose" function in the List module does exactly that.
However, a list may not be the best choice here; an array would
probably be better.
--
Glynn Clements
participants (3)
-
cris cris
-
Glynn Clements
-
jefu