Question about lists

jefu jefu@jefu.net
Sun, 19 Jan 2003 10:28:36 -0800


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)