{-# LANGUAGE BangPatterns #-} import Data.List import Data.Ratio import Control.Arrow import Control.Monad bernoulli :: Integer -> Rational bernoulli = genericIndex $ map head $ iterate ((*) `zipWith` enumFrom 1 <<< zipWith subtract `ap` tail) $ recip `map` enumFrom 1