Example in ML
Function to compute factorials
fun fact(0) = 1
| fact(n) = n * fact(n-1)
Alternative implementation
fun kfact(0, k) = k
| kfact(n, k) =
kfact(n-1, k*n)
fun fact(n) = kfact(n, 1)
Why the difference?
Previous slide
Next slide
Back to first slide
View graphic version