+import Normed
+
+import NumericPrelude hiding (abs)
+import qualified Algebra.Algebraic as Algebraic
+import qualified Algebra.Absolute as Absolute
+import qualified Algebra.Additive as Additive
+import qualified Algebra.Ring as Ring
+import Algebra.Absolute (abs)
+import qualified Algebra.Field as Field
+import qualified Algebra.RealField as RealField
+import qualified Algebra.RealRing as RealRing
+import qualified Algebra.ToRational as ToRational
+import qualified Algebra.Transcendental as Transcendental
+import qualified Prelude as P
+
+data Mat v w a = (Vector v (w a), Vector w a) => Mat (v (w a))
+type Mat1 a = Mat D1 D1 a
+type Mat2 a = Mat D2 D2 a
+type Mat3 a = Mat D3 D3 a
+type Mat4 a = Mat D4 D4 a
+
+-- We can't just declare that all instances of Vector are instances of
+-- Eq unfortunately. We wind up with an overlapping instance for
+-- w (w a).
+instance (Eq a, Vector v Bool, Vector w Bool) => Eq (Mat v w a) where
+ -- | Compare a row at a time.
+ --
+ -- Examples:
+ --
+ -- >>> let m1 = fromList [[1,2],[3,4]] :: Mat2 Int
+ -- >>> let m2 = fromList [[1,2],[3,4]] :: Mat2 Int
+ -- >>> let m3 = fromList [[5,6],[7,8]] :: Mat2 Int
+ -- >>> m1 == m2
+ -- True
+ -- >>> m1 == m3
+ -- False
+ --
+ (Mat rows1) == (Mat rows2) =
+ V.and $ V.zipWith comp rows1 rows2
+ where
+ -- Compare a row, one column at a time.
+ comp row1 row2 = V.and (V.zipWith (==) row1 row2)
+
+
+instance (Show a, Vector v String, Vector w String) => Show (Mat v w a) where
+ -- | Display matrices and vectors as ordinary tuples. This is poor
+ -- practice, but these results are primarily displayed
+ -- interactively and convenience trumps correctness (said the guy
+ -- who insists his vector lengths be statically checked at
+ -- compile-time).
+ --
+ -- Examples:
+ --
+ -- >>> let m = fromList [[1,2],[3,4]] :: Mat2 Int
+ -- >>> show m
+ -- ((1,2),(3,4))
+ --
+ show (Mat rows) =
+ "(" ++ (intercalate "," (V.toList row_strings)) ++ ")"
+ where
+ row_strings = V.map show_vector rows
+ show_vector v1 =
+ "(" ++ (intercalate "," element_strings) ++ ")"
+ where
+ v1l = V.toList v1
+ element_strings = P.map show v1l
+