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

Copyright(c) Hans Hoglund 2012
LicenseBSD-style
Maintainerhans@hanshoglund.se
Stabilitystable
Portabilitynon-portable Provides a monoid for calculating arithmetic means.
Safe HaskellNone
LanguageHaskell2010

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 -> a Source

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

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

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