Functions and lambda expressions

A lambda expression is one kind of anonymous function, which means it doesn't have a name attached to it. But if we want to create a function which can be called, we can use the fun keyword with a lambda expression. We can pass the input parameter in the lambda function, which is created using the fun keyword. This function is quite similar to a normal F# function. Let's see a normal F# function and a lambda function:

// Normal F# function
let addNumbers a b = a+b
// Evaluating values
let sumResult = addNumbers 5 6
// Lambda function and evaluating values
let sumResult = (fun (a:int) (b:int) -> a+b) 5 6
// Both the function will return value sumResult = 11
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset