Member-only story

Functional Programming

Higher order functions

What it is and how we can benefit from using it in our program?

Donald Le

--

Photo by Camylla Battani on Unsplash

Higher order functions infer a way of programming that we can pass function to another function as parameter, or even return function from another function. It gives us a very flexible way of tackling problems. In this post we will go through how to apply higher order functions in several programming languages.

First, let’s see how Haskell, a purely functional programming apply higher order functions. Below is a example for finding the maximum number from the list using recursion. In the function, the return of this function is its own function.

Here we define the input of function is a list of values ( not necessarily is integers) , then return the max value of the list. If the input value is an empty List, throw error. We check whether the each remaining element of the list is higher than the first element, if it is we include that in the list. Then we call that function recursively.

--

--

No responses yet