Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disambiguation of higher kinded type vs higher order type

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:

  • higher order type
  • higher kinded type
  • higher order kind

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:

  • higher-order-types
  • higher-kinded-types

However, there is no tag wiki for both of them.

like image 570
Stefan Dollase Avatar asked Jun 23 '16 23:06

Stefan Dollase


People also ask

Why are higher Kinded types useful?

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.

What are higher Kinded types Haskell?

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.

What languages support higher Kinded types?

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.

Does rust have higher Kinded types?

Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust.


1 Answers

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.

Higher kinded type

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.

Higher rank type

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.

like image 191
Stefan Dollase Avatar answered Dec 15 '22 08:12

Stefan Dollase