Haskell package for sampling from standard probability distributions

Well, if you want to be able to write code like this:

do n <- poisson lambda
   xs <- replicateM n $ normal mu sigma
   return $ maximum xs

then you presumably want to use random-fu:

import Control.Monad
import Data.Random
import Data.Random.Distribution.Poisson
import Data.Random.Distribution.Normal

foo :: RVar Double
foo = do
  n <- poisson lambda
  xs <- replicateM (n+1) $ normal mu sigma
  return $ maximum xs

  where lambda = 10 :: Double
        mu = 0
        sigma = 6

main :: IO ()
main = print =<< replicateM 10 (sample foo)

I'm not sure that lack of updates over the past three years should be a deciding factor. Have there really been that many exciting advances in the world of gamma distributions?

Actually, it looks like mwc-probability works about the same:

import Control.Monad
import System.Random.MWC.Probability

foo :: Prob IO Double
foo = do
  n <- poisson lambda
  xs <- replicateM (n+1) $ normal mu sigma
  return $ maximum xs

  where lambda = 10 :: Double
        mu = 0
        sigma = 6

main :: IO ()
main = do
  gen <- createSystemRandom
  print =<< replicateM 10 (sample foo gen)

Tags:

Haskell

Random