Talk:Haskell/Polymorphism

Higher Rank types
Our example  is said to have a rank-2 type. There are other ranks as well. Counting begins with ordinary polymorphic functions like

id :: forall a. a -> a  map :: forall a. [a] -> [a]

which are said to have rank-1 types. Functions with rank-1 types as arguments have rank-2 types. Examples include

f2 :: (forall a. a -> a -> a) -> Int -> Int g2 :: (forall a. Eq a => [a] -> a -> Bool) -> Int -> Int

A function like

f3 :: ((forall a. a -> a -> a) -> Int) -> Bool -> Bool

with a rank-2 type on the left of the function arrow is said to have a rank-3 type and so on.

What rank does

const :: forall a. a -> (forall b. b -> a)

have? It's the same as

const :: forall a. forall b. a -> b -> a

and therefor a rank-1 type. In other words, a  can be moved to the front when it's on the right of a function arrow, i.e. in the result position. Only quantifiers on the left of a function arrow, that is in the argument position, increase the rank and cannot be moved to the front.

Other types of polymorphism
At the end of the article: "ad-hoc polymorphism = different behavior depending on type s. => Haskell type classes"

Actually I think haskell type classes are an example of Bounded parametric polymorphism


 * So if I understand correctly Haskell does not have ad hoc parametricism; and that this section should describe type classes but under the section titled "Bounded parametric polymorphism". —Srid  🍁 01:29, 16 November 2019 (UTC)

Need Clarification?
In GHC 7.0.4 I could not find an example function that satisfied the code below provided in the main text.

However the below will run.


 * The only candidate for  there is  . It might be worth it noting that in the text itself. --Duplode (discuss • contribs) 03:39, 6 May 2019 (UTC)