[Haskell-cafe] First questions!

Daniel Fischer daniel.is.fischer at web.de
Thu Sep 2 08:53:01 EDT 2010


On Thursday 02 September 2010 14:49:12, Eoin C. Bairéad wrote:
> Example 2
>
> Prelude> let fac n = if n == 0 then 1 else n * fac (n-1)
>
> How does it know to stop ?

It tests for n == 0. If that returns True, the recursion stops.

> and why does fac 2.5 hang?
>

Because 2.5 is not an integer, so fac gets called with
2.5
1.5
0.5
-0.5
-1.5
-2.5
...
but never with 0, so you get infinite recursion.



More information about the Haskell-Cafe mailing list