]> gitweb.michael.orlitzky.com - numerical-analysis.git/blob - src/Vector.hs
Add a Vector class and make TwoTuple (and several base types) instances of it.
[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 Vector a where
11 norm :: RealFrac b => a -> b
12
13 -- Define instances for common numeric types.
14 instance Vector Integer where
15 norm = fromInteger
16
17 instance Vector Rational where
18 norm = fromRational
19
20 instance Epsilon e => Vector (BigFloat e) where
21 norm = fromRational . toRational
22
23 instance Vector Double where
24 norm = fromRational . toRational