In a previous question I asked Why can the Monad interface not be declared in Java?. There, I received a comment from Brian Goetz saying that I should have called "higher order types" "higher kinded types".
Now, I read more about type systems and I understand the concept of higher kinded types. However, I am still confused by the terms. I tried to disambiguate them by myself using Google, however there does not seem to be a clear answer. Thus, my question is what is the exact meaning of the following terms:
Do all three terms exist? Is there a difference between them? What is the difference? Does the meaning vary between programming languages?
I also noticed that StackOverflow has multiple tags:
However, there is no tag wiki for both of them.
Higher-kinded types are useful when we want to create a container that can hold any type of items; we don't need a different type for each specific content type. As we already saw, Collection (in our previous example) allows various entity types.
Higher-kinded types are types with kind signatures that have parenthesis somewhere on the left side, like this: (* -> *) -> * -> * . This means that they are types that take a type like Maybe as an argument. In other words, they abstract over polymorphic types. A common example is a type for any collection.
Haskell has good support for higher kinded types. Every type constructor such as they [] can be used as a "first class type". This is specifically relevant to typeclasses such as the Functor typeclass. Each of those instances are implementations of the Functor class for a particular higher kinded type.
Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust.
Following this blog post, the term higher order type seems to be the common term for higher kinded type and higher rank type. higher order kind is probably a term that I just made up when I was confused.
With higher kinded types, it is possible to receive a type parameter that itself is a generic type:
interface Foo<T<_>> {
T<String> get();
}
This is what is necessary to declare the Monad
interface.
With higher rank types, it is possible to receive a parameter whose type still contains unspecified type parameters:
interface Bar {
void foobar(<E> List<E> list);
}
Unfortunately, higher rank type checking/inference is undecidable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With