Scala:类型参数中的问号 [英] Scala: question marks in type parameters

查看:72
本文介绍了Scala:类型参数中的问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解以下代码(来自 Scalaz 库):

I'm trying to understand the following piece of code (from the Scalaz library):

def kleisliIdApplicative[R]: Applicative[Kleisli[Id, R, ?]] = ...

我假设 T[P0, ?] 形式的类型是一个带参数的类型构造函数.但是,我找不到解释在类型参数中使用问号的文档.

I'm assuming that a type of the form T[P0, ?] is a type-constructor that takes a parameter. However I'm no able to find documentation that explains the usage of question marks in type parameters.

一个相关的问题是问号和下划线有什么区别?

A related question is what is the difference between the question mark and an underscore?

有没有地方记录了所有这些内容?

Is there a place where all this is well-documented?

推荐答案

问号语法来自一个名为 kind-projector.

The question mark syntax comes from a compiler plugin called kind-projector.

您可以在此处看到它包含在 scalaz 构建中:https://github.com/scalaz/scalaz/blob/series/7.3.x/project/build.scala#L310

You can see it being included in the scalaz build here: https://github.com/scalaz/scalaz/blob/series/7.3.x/project/build.scala#L310

插件翻译

Kleisli[Id, R, ?]

进入(大致)

({type L[A] = Kleisli[Id, R, A]})#L

这是表达类型 lambda 的一种相当复杂的方式(但不幸的是 Scala 中的唯一方式),即部分应用的类型构造函数.

which is a rather convoluted way (but unfortunately the only way in Scala) of expressing a type lambda, i.e. a partially applied type constructor.

这篇关于Scala:类型参数中的问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆