The final code is on Github. I recently spent some time trying to learn Haskell, when I stumbled across the concept of probabilistic functional programming, originally based on this PFP library. Due to Haskell’s syntax sugar for monad computations, expressing probability distributions as monads allows you to implement something like a mini probabilistic programming language in less than 100 lines