Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a higher kinded type in Scala?

Having following definition

type MyMap = Map[String, List[Map[Int, String]]] 

Can Map be defined as a higher kinded type ?

like image 805
Lukasz Avatar asked May 08 '12 13:05

Lukasz


People also ask

What is the meaning of kind in Scala?

"Kind" is a word used to classify types and type constructors according to their level of abstractness. Concrete, fully specified types such as `Int` and `Option[Int]` are called "proper types" and denoted as `A` using Scala notation, or with the `*` symbol.

What is the use of higher kinded in Java?

One use case of higher-kinded types is in creating polymorphic containers. 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 the most popular Scala projects?

Scalaz, one of the most popular Scala projects, uses higher-kinded types to extend the core Scala library for functional programming. 4.2. Polymorphic Containers

What are the different types of variances in Scala?

Scala type systems contain variances like invariant, covariance and contravariance but the higher kinded type is different from them. We can either create custom type classes in Scala or we can use some of the existing Scala type classes like List [T], Option [T] and more.


1 Answers

What you have is not a higher-kinded type, but it could be quite easily modified to be such.

type MyMap2[A,B,C] = Map[A, List[Map[B, C]]]

Now, we can create MyMap again by providing type parameters.

type MyMap = MyMap2[String, Int, String]

"Higher-kinded" just means that it is a type that is uninhabited, and needs to be provided with other types in order to create an inhabitable type.

like image 107
Dan Burton Avatar answered Oct 15 '22 09:10

Dan Burton