average-0.6: An average (arithmetic mean) monoid.

Portabilitynon-portable Provides a monoid for calculating arithmetic means.
Stabilitystable
Maintainerhans@hanshoglund.se
Safe HaskellNone

Data.Monoid.Average

Description

 

Synopsis

Documentation

newtype Average a Source

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

Constructors

Average 

Fields

getAverage :: [a]
 

average :: Fractional a => Average a -> aSource

Return the average of all monoidal components. If given mempty, return zero.

maybeAverage :: Fractional a => Average a -> Maybe aSource

Return the average of all monoidal components. If given mempty, return Nothing.