Метод (правых) прямоугольников:
equidistantPoints a b n = [a, a + h .. b]
where h = (b - a) / n
squareIntegrateR f a b n =
(sum (map f (tail (equidistantPoints a b n)))) * h
where h = (b - a) / n
main = do
print ( squareIntegrateR (\x -> cos x) 0 (pi/2) 100000 )
print ( squareIntegrateR (\x -> x) 0 (pi/2) 10000 )
print ( x*x/2 ) where x = pi/2
Проверка:
# ghc -o int int.hs && ./int
0.999992145996432
1.2338239201912735
1.2337005501361697