Deterministic and probabilistic values

- type Event a = a -> Bool
- oneOf :: Eq a => [a] -> Event a
- just :: Eq a => a -> Event a
- newtype T prob a = Cons {
- decons :: [(a, prob)]

- certainly :: Num prob => a -> T prob a
- errorMargin :: RealFloat prob => prob
- approx :: (RealFloat prob, Ord a) => T prob a -> T prob a -> Bool
- lift :: Num prob => ([(a, prob)] -> [(a, prob)]) -> T prob a -> T prob a
- size :: T prob a -> Int
- check :: RealFloat prob => T prob a -> T prob a
- cons :: RealFloat prob => [(a, prob)] -> T prob a
- sumP :: Num prob => [(a, prob)] -> prob
- sortP :: Ord prob => [(a, prob)] -> [(a, prob)]
- sortElem :: Ord a => [(a, prob)] -> [(a, prob)]
- norm :: (Num prob, Ord a) => T prob a -> T prob a
- norm' :: (Num prob, Ord a) => [(a, prob)] -> [(a, prob)]
- norm'' :: (Num prob, Ord a) => [(a, prob)] -> [(a, prob)]
- pretty :: (Ord a, Show a, Num prob, Ord prob) => (prob -> String) -> T prob a -> String
- (//%) :: (Ord a, Show a) => T Rational a -> () -> IO ()
- type Spread prob a = [a] -> T prob a
- choose :: Num prob => prob -> a -> a -> T prob a
- enum :: Fractional prob => [Int] -> Spread prob a
- relative :: Fractional prob => [prob] -> Spread prob a
- shape :: Fractional prob => (prob -> prob) -> Spread prob a
- linear :: Fractional prob => Spread prob a
- uniform :: Fractional prob => Spread prob a
- negExp :: Floating prob => Spread prob a
- normal :: Floating prob => Spread prob a
- extract :: T prob a -> [a]
- map :: (Num prob, Ord b) => (a -> b) -> T prob a -> T prob b
- unfold :: (Num prob, Ord a) => T prob (T prob a) -> T prob a
- cond :: Num prob => T prob Bool -> T prob a -> T prob a -> T prob a
- truth :: Num prob => T prob Bool -> prob
- (?=<<) :: Fractional prob => (a -> Bool) -> T prob a -> T prob a
- (>>=?) :: Fractional prob => T prob a -> (a -> Bool) -> T prob a
- data Select a
- above :: (Num prob, Ord prob, Ord a) => prob -> T prob a -> T prob (Select a)
- fromFreqs :: Fractional prob => [(a, prob)] -> T prob a
- filter :: Fractional prob => (a -> Bool) -> T prob a -> T prob a
- selectP :: (Num prob, Ord prob) => T prob a -> prob -> a
- scanP :: (Num prob, Ord prob) => prob -> [(a, prob)] -> a
- (??) :: Num prob => Event a -> T prob a -> prob
- expected :: Num a => T a a -> a
- variance :: Num a => T a a -> a
- stdDev :: Floating a => T a a -> a

# Events

# Distributions

Probability disribution

The underlying data structure is a list.
Unfortunately we cannot use a more efficient data structure
because the key type must be of class `Ord`

,
but the `Monad`

class does not allow constraints for result types.
The Monad instance is particularly useful
because many generic monad functions make sense here,
monad transformers can be used
and the monadic design allows to simulate probabilistic games in an elegant manner.

We have the same problem like making Data.Set an instance of `Monad`

,
see http://www.randomhacks.net/articles/2007/03/15/data-set-monad-haskell-macros

If you need efficiency, you should remove redundant elements by `norm`

.
`norm`

converts to `Data.Map`

and back internally
and you can hope that the compiler fuses the lists with the intermediate Map structure.

Fractional prob => C prob (T prob) | |

Num prob => Monad (T prob) | |

Functor (T prob) | |

(Num prob, Ord prob, Random prob) => C (T prob) | |

Eq (T prob a) | |

(Num prob, Ord prob, Ord a, Fractional a) => Fractional (T prob a) | |

(Num prob, Ord prob, Ord a, Num a) => Num (T prob a) | |

(Num prob, Ord prob, Ord a, Show a) => Show (T prob a) | |

(ToFloat prob, Expected a) => Expected (T prob a) |

errorMargin :: RealFloat prob => probSource

approx :: (RealFloat prob, Ord a) => T prob a -> T prob a -> BoolSource

Check whether two distributions are equal when neglecting rounding errors.
We do not want to put this into an `Eq`

instance,
since it is not exact equivalence
and it seems to be too easy to mix it up with `liftM2 (==) x y`

.

## Auxiliary functions for constructing and working with distributions

cons :: RealFloat prob => [(a, prob)] -> T prob aSource

can fail because of rounding errors, better use `fromFreqs`

## Normalization = grouping

pretty :: (Ord a, Show a, Num prob, Ord prob) => (prob -> String) -> T prob a -> StringSource

pretty printing

# Spread: functions to convert a list of values into a distribution

enum :: Fractional prob => [Int] -> Spread prob aSource

relative :: Fractional prob => [prob] -> Spread prob aSource

Give a list of frequencies, they do not need to sum up to 1.

shape :: Fractional prob => (prob -> prob) -> Spread prob aSource

linear :: Fractional prob => Spread prob aSource

uniform :: Fractional prob => Spread prob aSource

unfold :: (Num prob, Ord a) => T prob (T prob a) -> T prob aSource

unfold a distribution of distributions into one distribution,
this is `join`

with normalization.

conditional distribution

(?=<<) :: Fractional prob => (a -> Bool) -> T prob a -> T prob aSource

conditional probability, identical to `Dist.filter`

(>>=?) :: Fractional prob => T prob a -> (a -> Bool) -> T prob aSource

`Dist.filter`

in infix form.
Can be considered an additional monadic combinator,
which can be used where you would want `Control.Monad.guard`

otherwise.

filtering distributions

fromFreqs :: Fractional prob => [(a, prob)] -> T prob aSource