Skip to content

test_22_local_function

David Pollak edited this page Jan 13, 2012 · 1 revision

Test local function

This is an example of a local function inside the f function. The fact function is local (it is not visible outside f and cannot be called outside f). Further, the n parameter to f is shadowed in fact.

// calculate the factorial of n
f n =
  fact n = if n == 0 then 1 else n * fact(n - 1)
  fact n

// invoke the function
res = f 8