Matrix transposition: Difference between revisions

Content added Content deleted
(→‎{{header|Scheme}}: apparently, apply is variadic)
(Added Haskell example)
Line 196: Line 196:
writefln(" n (m's transpose) = ", n.toString()) ;
writefln(" n (m's transpose) = ", n.toString()) ;
}</pre>
}</pre>

=={{header|Haskell}}==

For matrices represented as lists, there's ''transpose'':

<pre>
*Main> transpose [[1,2],[3,4],[5,6]]
[[1,3,5],[2,4,6]]
</pre>

For matrices in arrays, one can use ''ixmap'':

<pre>
import Data.Array

swap (x,y) = (y,x)

transpArray :: (Ix a, Ix b) => Array (a,b) e -> Array (b,a) e
transpArray a = ixmap (swap l, swap u) swap a where
(l,u) = bounds a
</pre>

=={{header|IDL}}==
=={{header|IDL}}==