Copyright  (c) Hans Hoglund 2012 

License  BSDstyle 
Maintainer  hans@hanshoglund.se 
Stability  stable 
Portability  nonportable Provides a monoid for calculating arithmetic means. 
Safe Haskell  None 
Language  Haskell2010 
 newtype Average a = Average {
 getAverage :: [a]
 average :: Fractional a => Average a > a
 maybeAverage :: Fractional a => Average a > Maybe a
Documentation
A monoid for Average
values.
This is actually just the free monoid with an extra function average
for
extracing the (arithmetic) mean. This function is used to implement Real
,
so you can use Average
whenever a (Monoid
, Real
) is required.
>>>
toRational $ mconcat [1,2::Average Rational]
3 % 2>>>
toRational $ mconcat [1,2::Sum Rational]
3 % 1>>>
toRational $ mconcat [1,2::Product Rational]
2 % 1
Average  

Functor Average  
Applicative Average  
(Fractional a, Eq a) => Eq (Average a)  
Floating a => Floating (Average a)  
(Fractional a, Num a) => Fractional (Average a)  
Num a => Num (Average a)  
(Fractional a, Ord a) => Ord (Average a)  
(Real a, Fractional a) => Real (Average a)  
Show a => Show (Average a)  
Monoid (Average a)  
Semigroup (Average a)  
AffineSpace a => AffineSpace (Average a)  
VectorSpace a => VectorSpace (Average a)  
AdditiveGroup a => AdditiveGroup (Average a)  
Typeable (* > *) Average  
type Diff (Average a) = Average (Diff a)  
type Scalar (Average a) = Scalar a 
average :: Fractional a => Average a > a Source
Return the average of all monoidal components. If given mempty
, return zero.
maybeAverage :: Fractional a => Average a > Maybe a Source