Declaring and calling inner functions

Category:
Functions
Description: Declaring and calling functions within the body of another function
Code:
let FunctionSample2() =
let even n = (n%2 = 0)
let tick x = printfn "tick %d" x
let tock x = printfn "tock %d" x
let choose f g h x = if f x then g x else h x
let ticktock = choose even tick tock // ticktock is a function built out of other functions using 'choose'
for i = 0 to 10 do
ticktock i


Execution Result:
tick 0
tock 1
tick 2
tock 3
tick 4
tock 5
tick 6
tock 7
tick 8
tock 9
tick 10

Last edited Sep 14, 2011 at 2:25 AM by ttliu2000, version 1

Comments

No comments yet.