úÎO    (c) William Yager 2015MIT%will (dot) yager (at) gmail (dot) com provisionalportableNoneB6A probability distribution with probabilities of type p and outcomes/events of type o.2The sum of all probabilities in the distribution. O(1)1Normalizes the distribution. After normalizing,  distribution is 1. O(n)4Insert an outcome into the distribution. Inserting (o,p1) and (o,p2)8 results in the same sampled distribution as inserting  (o,p1+p2).  O(log(n)) amortized.The empty distribution. O(1) O(n*log(n)) amortized.  O(n*log(n)). 1Assumes there are no repeated items in the list.  O(n*log(n)) amortized. %Doesn't bother to eliminate repeats. O(n)âA right-associative fold on the tree structure, including the probabilities. Note that outcomes may be repeated within the data structure. If you want identical outcomes to be lumped together, fold on the list produced by . O(n).OCreates a new distribution that's the joint distribution of the two provided.  O(nm*log(nm)) amortized. ^Creates a new distribution by summing the probabilities of the outcomes in the two provided. O((n+m)log(n+m)) amortized. ;Take a sample from the distribution. Can be used with e.g. evalRand or  evalRandIO from Control.Monad.Random.  O(log(n)); for a uniform distribution (worst case), but approaches O(1)# with less balanced distributions. YA series of tests on the internal structure of the distribution. For debugging purposes.#    ! "       ! "#      !"# Dist-0.1.0.0 Numeric.Probability.Distribution Distributioncumulate normalizeinsertemptyfromListtoList foldrWithPjointsumsample invariants fromUniqList toRepeatListDTreeLeaf outcomeOfprobOfsumOfcountOfleftOfrightOf normalize'reducefoldrTreeWithP insertTreerandomPositiveUpto sampleTree sizeInvariant sumInvariant heapInvariant zeroInvariant$fShowDistribution