--- | The number of rows in the matrix.
-nrows :: (Matrix a) -> Int
-nrows (Matrix rows) = V.length rows
-
--- | The number of columns in the first row of the matrix.
-ncols :: (Matrix a) -> Int
-ncols (Matrix rows)
- | V.length rows == 0 = 0
- | otherwise = V.length (rows V.! 0)
-
--- | Return the vector of @m@'s columns.
-columns :: (Matrix a) -> (Columns a)
-columns m =
- V.fromList [column m i | i <- [0..(ncols m)-1]]
-
--- | Transose @m@; switch it's columns and its rows.
-transpose :: (Matrix a) -> (Matrix a)
-transpose m =
- Matrix (columns m)
-
-instance Show a => Show (Matrix a) where
- show (Matrix rows) =
- concat $ V.toList $ V.map show_row rows
- where show_row r = "[" ++ (show r) ++ "]\n"
-
-instance Functor Matrix where
- f `fmap` (Matrix rows) = Matrix (V.map (fmap f) rows)
-
-
--- | Vector addition.
-vplus :: Num a => (V.Vector a) -> (V.Vector a) -> (V.Vector a)
-vplus xs ys = V.zipWith (+) xs ys
-
--- | Vector subtraction.
-vminus :: Num a => (V.Vector a) -> (V.Vector a) -> (V.Vector a)
-vminus xs ys = V.zipWith (-) xs ys
-
--- | Add two vectors of rows.
-rowsplus :: Num a => (Rows a) -> (Rows a) -> (Rows a)
-rowsplus rs1 rs2 =
- V.zipWith vplus rs1 rs2
-
--- | Subtract two vectors of rows.
-rowsminus :: Num a => (Rows a) -> (Rows a) -> (Rows a)
-rowsminus rs1 rs2 =
- V.zipWith vminus rs1 rs2
-
--- | Matrix multiplication.
-mtimes :: Num a => (Matrix a) -> (Matrix a) -> (Matrix a)
-mtimes m1@(Matrix rows1) m2@(Matrix rows2) =
- Matrix (V.fromList rows)
+-- | Transpose @m@; switch it's columns and its rows. This is a dirty
+-- implementation.. it would be a little cleaner to use imap, but it
+-- doesn't seem to work.
+--
+-- TODO: Don't cheat with fromList.
+--
+-- Examples:
+--
+-- >>> let m = fromList [[1,2], [3,4]] :: Mat2 Int
+-- >>> transpose m
+-- ((1,3),(2,4))
+--
+transpose :: (Vector v (Vn w a),
+ Vector w (Vn v a),
+ Vector v a,
+ Vector w a)
+ => Mat v w a
+ -> Mat w v a
+transpose m = V.fromList column_list