This project is read-only.
Declaring and calling anonymous function lamda expressions

Category:
Functions
Description: Introduction to using lambda expressions
Code:
let FunctionSample3() =
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
for i = 0 to 10 do
// This is like the previous sample, but uses an anonymous lambda expression for
// the function that decides whether to tick or tock.
choose (fun n -> n%2 = 0) tick tock 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 3:26 AM by ttliu2000, version 1

Comments

No comments yet.