]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/TwoTuple.hs
Add 2d/3d wrapper types for easy pattern matching.
[numerical-analysis.git] / src / TwoTuple.hs
index 1b5e93e151f1f7d8b5f3774e454b4a4589c20b3b..becb11eb05435f5a3b45223a5d718475f32e9878 100644 (file)
@@ -6,7 +6,7 @@
 module TwoTuple
 where
 
-import Vector
+import Normed
 
 
 data TwoTuple a = TwoTuple a a
@@ -18,10 +18,17 @@ instance (Show a) => Show (TwoTuple a) where
 instance Functor TwoTuple where
   f `fmap` (TwoTuple x1 y1) = TwoTuple (f x1) (f y1)
 
-instance (RealFloat a) => Vector (TwoTuple a) where
+instance (RealFloat a) => Normed (TwoTuple a) where
   -- The standard Euclidean 2-norm. We need RealFloat for the square
   -- root.
-  norm (TwoTuple x1 y1) = fromRational $ toRational (sqrt(x1^2 + y1^2))
+  norm (TwoTuple x y) = fromRational $ toRational (sqrt(x^2 + y^2))
+
+  -- The infinity norm, i.e. the maximum entry.
+  norm_infty (TwoTuple x y) =
+    fromRational $ max absx absy
+    where
+      absx = abs (toRational x)
+      absy = abs (toRational y)
 
 -- | It's not correct to use Num here, but I really don't want to have
 --   to define my own addition and subtraction.