Scala 问号是什么意思?
我有以下代码函数:Scala 问号是什么意思?,scala,kind-projector,Scala,Kind Projector,我有以下代码函数: def jsonOrBadRequest[F[_] : Monad](service: HttpService[F]) : HttpService[F] = { object dsl extends Http4sDsl[F] import dsl._ Kleisli[OptionT[F, ?], Request[F], Response[F]] { req => req.contentType match {
def jsonOrBadRequest[F[_] : Monad](service: HttpService[F])
: HttpService[F]
= {
object dsl extends Http4sDsl[F]
import dsl._
Kleisli[OptionT[F, ?], Request[F], Response[F]] { req =>
req.contentType match {
case Some(s) =>
if (s != `Content-Type`(MediaType.`application/json`))
OptionT.liftF(BadRequest("Malformed format."))
else
service(req)
case None =>
OptionT.liftF(BadRequest("Malformed format."))
}
}
}
我想知道,问号是什么意思?它来自库。这不是特殊的Scala语法<代码>?与其他任何东西一样是有效的标识符<代码>种类投影仪使用它来声明类型级别的lambda。比如说,
(示例直接取自)
?
是一个有效的标识符,就像a
、T
和烤箱中的字号一样。我想kind projector
以某种特定的方式定义了?
,所以请查看他们的文档。这不是一种特殊的Scala语法。在哪种情况下我应该使用问号?你能给我展示一些用例吗,例如或者[Int,+?]
。左边是typeInt
,右边是type of?在这种情况下,我应该使用问句而不是type变量。
Tuple2[?, Double] // equivalent to: type R[A] = Tuple2[A, Double]
Either[Int, +?] // equivalent to: type R[+A] = Either[Int, A]
Function2[-?, Long, +?] // equivalent to: type R[-A, +B] = Function2[A, Long, B]
EitherT[?[_], Int, ?] // equivalent to: type R[F[_], B] = EitherT[F, Int, B]