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

Copyright (c) Hans Hoglund 2012 BSD-style hans@hanshoglund.se stable non-portable Provides a monoid for calculating arithmetic means. None Haskell2010

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 FieldsgetAverage :: [a]

Instances

 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

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