Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: question marks in type parameters

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

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

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?

like image 975
Damian Nadales Avatar asked Jul 27 '16 17:07

Damian Nadales


1 Answers

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

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

The plugin translates

Kleisli[Id, R, ?]

into (roughly)

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

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.

like image 105
Gabriele Petronella Avatar answered Sep 30 '22 07:09

Gabriele Petronella