1 {-# LANGUAGE FlexibleInstances #-}
3 -- | The 'Vector' class represents elements of a normed vector
4 -- space. We define instances for all common numeric types.
8 import Data.Number.BigFloat
10 class (Num a) => Vector a where
11 norm_2 :: RealFrac b => a -> b
12 norm_infty :: RealFrac b => a -> b
14 -- Define instances for common numeric types.
15 instance Vector Integer where
17 norm_infty = fromInteger
19 instance Vector Rational where
21 norm_infty = fromRational
23 instance Epsilon e => Vector (BigFloat e) where
24 norm_2 = fromRational . toRational
25 norm_infty = fromRational . toRational
27 instance Vector Double where
28 norm_2 = fromRational . toRational
29 norm_infty = fromRational . toRational