I am not really proficient in Haskell, so this might be a very easy question.
What language limitation do Rank2Types solve? Don’t functions in Haskell already support polymorphic arguments?
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.
They do, but only of rank 1. This means that while you can write a function that takes different types of arguments without this extension, you can’t write a function that uses its argument as different types in the same invocation.
For example the following function can’t be typed without this extension because
gis used with different argument types in the definition off:Note that it’s perfectly possible to pass a polymorphic function as an argument to another function. So something like
map id ["a","b","c"]is perfectly legal. But the function may only use it as monomorphic. In the examplemapusesidas if it had typeString -> String. And of course you can also pass a simple monomorphic function of the given type instead ofid. Without rank2types there is no way for a function to require that its argument must be a polymorphic function and thus also no way to use it as a polymorphic function.