]> gitweb.michael.orlitzky.com - numerical-analysis.git/blob - src/Vector.hs
Rename "norm" to "norm_2" in the Vector class.
[numerical-analysis.git] / src / Vector.hs
1 {-# LANGUAGE FlexibleInstances #-}
2
3 -- | The 'Vector' class represents elements of a normed vector
4 -- space. We define instances for all common numeric types.
5 module Vector
6 where
7
8 import Data.Number.BigFloat
9
10 class (Num a) => Vector a where
11 norm_2 :: RealFrac b => a -> b
12 norm_infty :: RealFrac b => a -> b
13
14 -- Define instances for common numeric types.
15 instance Vector Integer where
16 norm_2 = fromInteger
17 norm_infty = fromInteger
18
19 instance Vector Rational where
20 norm_2 = fromRational
21 norm_infty = fromRational
22
23 instance Epsilon e => Vector (BigFloat e) where
24 norm_2 = fromRational . toRational
25 norm_infty = fromRational . toRational
26
27 instance Vector Double where
28 norm_2 = fromRational . toRational
29 norm_infty = fromRational . toRational