Hi!

2010/9/2 Eoin C. BairĂ©ad <[email protected]>

> Example 2
>
> Prelude> let fac n = if n == 0 then 1 else n * fac (n-1)
>
> How does it know to stop ?
>

When fac is called with n=0 it returns 1 and stops the recursion.


> and why does fac 2.5 hang?
>

fac, as you defined it, is only defined for integers. As you repeatedly
subtract 1 from n you will never get to 0 (you will get to 0.5 and then
-0.5) and thus the recursion will never terminate.\
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to