]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Vector.hs
Add a Vector class and make TwoTuple (and several base types) instances of it.
[numerical-analysis.git] / src / Vector.hs
diff --git a/src/Vector.hs b/src/Vector.hs
new file mode 100644 (file)
index 0000000..e608a50
--- /dev/null
@@ -0,0 +1,24 @@
+{-# LANGUAGE FlexibleInstances #-}
+
+-- | The 'Vector' class represents elements of a normed vector
+--   space. We define instances for all common numeric types.
+module Vector
+where
+
+import Data.Number.BigFloat
+
+class Vector a where
+  norm :: RealFrac b => a -> b
+
+-- Define instances for common numeric types.
+instance Vector Integer where
+  norm = fromInteger
+
+instance Vector Rational where
+  norm = fromRational
+
+instance Epsilon e => Vector (BigFloat e) where
+  norm = fromRational . toRational
+
+instance Vector Double where
+  norm = fromRational . toRational