X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;ds=sidebyside;f=src%2FVector.hs;fp=src%2FVector.hs;h=e608a509c505a35f1294618f5d83924a57d0ec30;hb=ff83c063ad5cdb1bf9476678a010aa0cfb782a8f;hp=0000000000000000000000000000000000000000;hpb=06c8df4932b9a46e48b3fc99c3bc44e787b182fc;p=numerical-analysis.git diff --git a/src/Vector.hs b/src/Vector.hs new file mode 100644 index 0000000..e608a50 --- /dev/null +++ b/src/Vector.hs @@ -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