Friday, February 27, 2009

Finding the factorial in haskell.

rangeProduct :: Float -> Float -> Float
rangeProduct m n
| m>n             = 0
| m==n            = m
| otherwise       = m * rangeProduct (m+1) n

--4.6 Factorial

factorial :: Float -> Float
factorial n
| n == 0          = 1
| otherwise       = rangeProduct 1 n

No comments:

Post a Comment