What does the question mark mean?

630 Views Asked by At

I have following code functions:

  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."))
      }
    }
  }

and wanted to know, what does the question mark mean? It is from the library https://github.com/non/kind-projector.

1

There are 1 best solutions below

2
Silvio Mayolo On

This is not special Scala syntax. ? is a valid identifier like anything else. kind-projector uses it to declare type-level lambdas. For example,

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]

(Examples taken directly from the kind-projector documentation)