I want to write a bernoulli function bernoulli:: Integer -> Rational
in haskell, using the following algorithm for calculating the bernoulli number for a given integer.
the functions "frac" and "binom" are used to calculate the binomial in the definition. this is what i have so far:
fact :: Integer -> Integer
fact i = foldr (*) 1 [1..i]
binom :: Integer -> Integer -> Integer
binom n k = (fact n) `div` (fact k* fact (n-k))
bernoulli :: Integer -> Rational
bernoulli 0 = 1
bernoulli i = ((binom i j) * (bernoulli j)) / (j - i - 1) where j = i-1
I've tried it a few different times now, but either the recursion doesn't work or the resulting Rational is wrong.