CPP 6
CPP 6
EXPERIMENT 6
AIM:- Demonstrate recursive function in Haskell.
THEORY:- Recursive functions play a central role in Haskell, and are used throughout computer science
and mathematics generally. Recursion is basically a form of repetition, and we can understand it by
making distinct what it means for a function to be recursive, as compared to how it behaves. A recursive
function simply means this: function that has the ability to invoke itself. And it behaves such that it
invokes itself only when a condition complete, as with an if/else/then expression, or a pattern match
which contains at least one base case that generates the recursion, as well as a recursive case which
causes the function to call itself, creating a loop
main ::10 ()
main=do
OUTPUT:
factorial n=ifn < 0 then error "Factorial is not defined for negative numbers"
else if n == 0 then 7
main = do
3628800