Looking through the Haskell Prelude, I see a function const:
const x _ = x
I can’t seem to find anything relevant regarding this function.
What’s the point? Can anyone give an example of where this function might be used?
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.
It’s useful for passing to higher-order functions when you don’t need all their flexibility. For example, the monadic sequence operator
>>can be defined in terms of the monadic bind operator asIt’s somewhat neater than using a lambda
and you can even use it point-free
although I don’t particularly recommend that in this case.