import Data.Ratio pascal :: [(Integer, Rational, Integer)] -> [(Integer, Rational, Integer)] pascal [] = [] pascal [x] = [x] pascal ((p1,b1,k1) : (p2,b2,k2) : ps) = (p1 + p2,b1,k1) : pascal ((p2,b2,k2) : ps) bernoulli' :: [(Integer, Rational, Integer)] -> Integer -> Integer -> Rational bernoulli' pascalBernK x n | x == n = let ((_,result,_):_) = pascalBernK in result | otherwise = bernoulli' (pascal tmp) (x+1) n where tmp = (1, sum [(p%1) * b / ((k-x-2)%1) | (p, b, k) <- pascalBernK], x+1) : pascalBernK bernoulli :: Integer -> Rational bernoulli = bernoulli' [(1, 1%1, 0)] 0