I need to calculate the product of all factorials from 1..n. When I call this function double_factorial (with at least 2 or 3 as args), it seems to be called for a moment, but nothing happens, and after a few seconds the GHCi just closes. What is wrong? Is there some infinite recursion that I can't see? Here is my code :
double_factorial :: Integer->Integer
double_factorial n
| n<0 = error "negative number is given"
| n==0 = 1
| otherwise = (factorial n)*(double_factorial n-1)
where
factorial :: Integer->Integer
factorial n
| n == 0 = 1
| otherwise = n*(factorial n-1)
(double_factorial n-1)
means ((double_factorial n) - 1)
so yes, it's an infinite recursion problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With