Higher-order functions (HOF)

One function can take an input argument as another function and it can return a function. This originated from calculus and is widely used in functional programming. Order can be determined by domain and range of order such as order 0 has no function data and order 1 has a domain and range of order 0, if order is higher than 1, it is called a higher-order function. For example, the ComplexCalc function takes another function as input and returns a different function as output:

open System
let sum y = x+x
let divide y = x/x
Let ComplexCalc func = (func 2)
Printfn(ComplexCalc sum) // 4
Printfn(ComplexCalc divide) //1

In the previous example, we created two functions, sum and divide. We pass these two functions as parameters to the ComplexCalc function, and it returns a value of 4 and 1, respectively.

..................Content has been hidden....................

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