2015-09-26 65 views
15

當詢問在Haskell的那種[Int][]我得到:問計一類的實物斯卡拉VS哈斯克爾

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

這是有道理的:第一個是正確的類型,第二個是更高的親屬型。

但是,當我做同樣的斯卡拉:

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. 

...它說都是高kinded類型。爲什麼第一個沒有被歸類爲合適的類型?這種差異的原因是什麼?

+2

似乎第一個少了點* *看到了'int'(它也談到'scala.collection.immutable.List' – Carsten

回答

6

似乎scala看到了List[Int][Int]部分非常清楚,但選擇忽略它,總是看「外部」型故意。

如果這是不正確的,那麼type ListOfInt = List[Int]其次:k -v ListOfInt將產生** -> *但事實並非如此:

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.