import Data.Ratio main :: IO () main = do mapM_ (print . map fromRational . dicePosteriors [4,6,8,12,20]) [[6], [6,4,8,7,7,2,6], [4,8,7,7,2,6], [6,8,7,7,5,4]] dicePosteriors :: [Integer] -> [Integer] -> [Ratio Integer] dicePosteriors suite xxs = f xxs where f (x:xs) = let zs = foldr p (p x [1,1..]) xs in map (/ sum zs) zs f _ = [] p x priors = zipWith (*) priors $ map (likelihood x) suite likelihood :: Integer -> Integer -> Ratio Integer likelihood x hypo = if hypo < x then 0 else 1 % hypo