]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Normed.hs
Replace the custom 'Vector' typeclass with 'Normed' everywhere.
[numerical-analysis.git] / src / Normed.hs
index b60c2b12fe84d51e0bf83b60ce0f958af55f7c10..7f4131aee78958b0938c907855a840ada4b47dfe 100644 (file)
@@ -7,10 +7,18 @@ where
 
 import Data.Number.BigFloat
 
-class Normed a where
+-- Since the norm is defined on a vector space, we should be able to
+-- add and subtract anything on which a norm is defined. Of course
+-- 'Num' is a bad choice here, but we really prefer to use the normal
+-- addition and subtraction operators.
+class (Num a) => Normed a where
   norm_p :: (Integral c, RealFrac b) => c -> a -> b
   norm_infty :: RealFrac b => a -> b
 
+  -- | The "usual" norm. Defaults to the Euclidean norm.
+  norm :: RealFrac b => a -> b
+  norm = norm_p (2 :: Integer)
+
 -- Define instances for common numeric types.
 instance Normed Integer where
   norm_p _ = fromInteger