What does the `*` mean in a generic type?

那年仲夏 提交于 2020-06-07 07:06:48

问题


I was learning Cats library and found * as a generic type, like that:

implicit def catsDataSemigroupKForValidated[A](implicit A: Semigroup[A]): SemigroupK[Validated[A, *]] =
  new SemigroupK[Validated[A, *]] {
    def combineK[B](x: Validated[A, B], y: Validated[A, B]): Validated[A, B] = x match {
      case v @ Valid(_) => v
      case Invalid(ix) =>
        y match {
          case Invalid(iy)  => Invalid(A.combine(ix, iy))
          case v @ Valid(_) => v
        }
    }
  }

My guess is that the * is used, because the combineK method return Validated[A, B] so there is no need to specify generic type. Or it could be Any type (like Inteliij is suggested). I would be very glad for your explanations.


回答1:


The cats code you are looking at is master branch, which is for Dotty (Scala 3). * is a type parameter placeholder in 3.0:

https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html

Note that it is already deprecated in 3.2 and removed in 3.3 in favor for _.



来源:https://stackoverflow.com/questions/61565393/what-does-the-mean-in-a-generic-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!