Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asking for a type's kind in Scala vs Haskell

When asking for the kind of [Int] and [] in Haskell I get:

Prelude> :k [Int]
[Int] :: *
Prelude> :k []
[] :: * -> *

which makes sense: the first one is a proper type and the second one is a higher kinded type.

But when I do the same in Scala:

scala> :k -v List[Int]
scala.collection.immutable.List's kind is F[+A]
* -(+)-> *
This is a type constructor: a 1st-order-kinded type.

scala> :k -v List
scala.collection.immutable.List's kind is F[+A]
* -(+)-> *
This is a type constructor: a 1st-order-kinded type.

... it says both are higher kinded types. Why the first one isn't classified as a proper type? What's the reason for this difference?

like image 566
miguel Avatar asked Sep 26 '15 18:09

miguel


1 Answers

It seems that scala sees the [Int] part in List[Int] perfectly well, but chooses to ignore it and always look at the "outer" type deliberately.

If this weren't true, then type ListOfInt = List[Int] followed by :k -v ListOfInt would yield * not * -> * but that's not the case:

scala> :k -v List
scala.collection.immutable.List's kind is F[+A]
* -(+)-> *
This is a type constructor: a 1st-order-kinded type.

scala> :k -v List[Int]
scala.collection.immutable.List's kind is F[+A]
* -(+)-> *
This is a type constructor: a 1st-order-kinded type.

scala> type ListOfInt = List[Int]
defined type alias ListOfInt

scala> :k -v ListOfInt
scala.collection.immutable.List's kind is F[+A]
* -(+)-> *
This is a type constructor: a 1st-order-kinded type.
like image 147
Erik Kaplun Avatar answered Oct 13 '22 15:10

Erik Kaplun