i went though several Haskell learning examples but i could not figure out how to write user defined higher order functions in Haskell
if we are taking a parameter as a function how the type of the function id defined?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let’s use the function
mapas a simple example.maptakes a function and a list and applies the function to all elements of the list. If you write the signature ofmap, it runs like this:First, you need a function. Any function is OK, so the type of the first argument is
a -> b. Then, you need a list of input values. Since the type of the list’s elements must fit to the function’s input, the type of the list is[a]. For the output: What is the result of a functiona -> bwhen applied to a value of typea? Right, it isb. So the result type is[b]. Assembled together, the type of our function runs like this:And is defined like this:
Does this help you to understand the concept of high order functions?