]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Normed.hs
Begin implementation of normed, fixed-length vectors.
[numerical-analysis.git] / src / Normed.hs
diff --git a/src/Normed.hs b/src/Normed.hs
new file mode 100644 (file)
index 0000000..b60c2b1
--- /dev/null
@@ -0,0 +1,29 @@
+{-# LANGUAGE FlexibleInstances #-}
+
+-- | The 'Normed' class represents elements of a normed vector
+--   space. We define instances for all common numeric types.
+module Normed
+where
+
+import Data.Number.BigFloat
+
+class Normed a where
+  norm_p :: (Integral c, RealFrac b) => c -> a -> b
+  norm_infty :: RealFrac b => a -> b
+
+-- Define instances for common numeric types.
+instance Normed Integer where
+  norm_p _ = fromInteger
+  norm_infty = fromInteger
+
+instance Normed Rational where
+  norm_p _ = fromRational
+  norm_infty = fromRational
+
+instance Epsilon e => Normed (BigFloat e) where
+  norm_p _ = fromRational . toRational
+  norm_infty = fromRational . toRational
+
+instance Normed Double where
+  norm_p _ = fromRational . toRational
+  norm_infty = fromRational . toRational