Assume there is a function called “smallerc”
smallerc :: Integer -> (Integer->Integer)
smallerc x y = if x <=y then x else y
Why not declare the function by using:
smallerc :: (Integer -> Integer) ->Integer
Thank you!
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.
The key to understanding currying is to understand that there is no such thing as a function with more than one argument. Every function in haskell has exactly one argument. But because of the right-associative properties of the
->operator, that’s not immediately clear.When you see this:
It is equivalent to this:
In both cases, the function takes an
Integerand returns a function. (The function returned is one that takes anIntegerand returns anInteger.) So this might be something like a simple mathematical operation; it takes anInteger(let’s say 5) and returns a function that takes anotherInteger(5 again) and adds it to the first one, and returns the result (10).But when you do this:
You’ve created something very different — a function that takes a function and returns an
Integer. This could also be a way of implementing a mathematical function; but instead of taking anIntegeras the first argument, it takes the mathematical operation itself! So for example, say you pass to this function a function that adds 5 to whatever is passed to it. This function then passes5to that function, and returns the result (10).