加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

要求在Scala对Haskell的类型

发布时间:2020-12-16 09:15:38 所属栏目:安全 来源:网络整理
导读:当要求 Haskell中的[Int]和[]类型时,我得到: Prelude :k [Int][Int] :: *Prelude :k [][] :: * - * 这是有道理的:第一个是正确的类型,第二个是较高类型. 但是当我在Scala中做同样的事情时: scala :k -v List[Int]scala.collection.immutable.List's kind
当要求 Haskell中的[Int]和[]类型时,我得到:

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

这是有道理的:第一个是正确的类型,第二个是较高类型.

但是当我在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.

它说两者都是较高种类的.为什么第一个不被归类为正确的类型?这个差异的原因是什么?

解决方法

看起来Scala很好地看到List [Int]中的[Int]部分,但是选择忽略它,并且总是仔细地看“外部”类型.

如果这不是真的,那么键入ListOfInt = List [Int],后跟:k -v ListOfInt将会产生* not * – > *但事实并非如此:

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读