Parametricity is the property that holds in the presence of parametric polymorphism. Parametricity states that the behavior of a function will be uniform across all concrete applications of that function. Parametricity tells us that the function:
id :: a -> a
const must return the first value—parametricity and the definition of the type require it!
f :: a -> a -> a
Here, f can only return the first or second value, nothing else, and it will always return one or the other consistently without changing. If the function f made use of + or *, its type would necessarily be constrained by the type class Num and thus be an example of ad-hoc, rather than parametric, polymorphism.
blahFunc :: b -> String
blahFunc totally ignores its argument and is effectively a constant value of type String that requires a throw-away argument for no reason.
convList :: a -> [a]
Unless the result is [], the resulting list has values that are all the same—and the list will always be the same length.
Parametricity is the property that holds in the presence of parametric polymorphism. Parametricity states that the behavior of a function will be uniform across all concrete applications of that function. Parametricity tells us that the function:
const
must return the first value—parametricity and the definition of the type require it!Here,
f
can only return the first or second value, nothing else, and it will always return one or the other consistently without changing. If the functionf
made use of+
or*
, its type would necessarily be constrained by the type classNum
and thus be an example of ad-hoc, rather than parametric, polymorphism.blahFunc
totally ignores its argument and is effectively a constant value of type String that requires a throw-away argument for no reason.Unless the result is
[]
, the resulting list has values that are all the same—and the list will always be the same length.