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