fork download
  1. import Data.Ratio
  2.  
  3. main :: IO ()
  4. main = do
  5. print $ dicePosteriors [6] [6]
  6. mapM_ (print . map fromRational . flip dicePosteriors [4,6,8,12,20])
  7. [[6], [6,4,8,7,7,2,6], [4,8,7,7,2,6], [6,8,7,7,5,4]]
  8.  
  9. dicePosteriors :: [Integer] -> [Integer] -> [Ratio Integer]
  10. dicePosteriors xxs suite = f xxs
  11. where
  12. f (x:xs) = g (p x [1,1..]) xs
  13. where
  14. g ys [] = ys
  15. g ys (h:t) = g (p h ys) t
  16. p x priors = map (/ n) zs
  17. where
  18. n = sum zs
  19. zs = zipWith (*) priors ls
  20. ls = map (likelihood x) suite
  21.  
  22. likelihood :: Integer -> Integer -> Ratio Integer
  23. likelihood x hypo
  24. | hypo < x = 0
  25. | otherwise = 1 % hypo
  26.  
Success #stdin #stdout 0s 6280KB
stdin
Standard input is empty
stdout
[1 % 1]
[0.0,0.39215686274509803,0.29411764705882354,0.19607843137254902,0.11764705882352941]
[0.0,0.0,0.9432484536722126,5.52061280612909e-2,1.5454182664965531e-3]
[0.0,0.0,0.91584527196901,8.040342579700499e-2,3.7513022339850646e-3]
[0.0,0.0,0.91584527196901,8.040342579700499e-2,3.7513022339850646e-3]