[Haskell-cafe] First questions!

Johan Tibell johan.tibell at gmail.com
Thu Sep 2 08:54:45 EDT 2010


Hi!

2010/9/2 Eoin C. Bairéad <ebairead at gmail.com>

> 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.\
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100902/3165514e/attachment.html


More information about the Haskell-Cafe mailing list