Questions tagged [kind-projector]

Scala compiler plugin for making type lambdas and polymorphic lambdas easier to write

Scala compiler plugin for making type lambdas (type projections) and polymorphic lambdas easier to write https://github.com/typelevel/kind-projector

27 questions
24
votes
5 answers

Is it possible to "curry" higher-kinded types in Scala?

Let's suppose I have a trait with two type parameters, e.g. trait Qux[A, B] and another trait with a higher-kinded type parameter, e.g. trait Turkle[C[_]] I'd like to be able to substitute a fixed value for one of the type parameters for Qux, so…
Scott Morrison
  • 3,100
  • 24
  • 39
7
votes
1 answer

Partially applied type lambda in Scala with kind projector

Consider the following type definition: trait LiftF[F[_], G[_]] { def liftF[A](fa: F[A]): G[A] } When providing a requirement for an implicit of this type in context bounds (using kind projector plugin) we have to write it like this: def func[A,…
7
votes
2 answers

Functor Instance for Type Constructor with Two Parameters in Scala

I have a class Foo with two parameters, and I am trying to write a Functor instance for Foo with the first parameter fixed, as follows: object Scratchpad { trait Functor[F[_]] { def fmap[A, B](f: A => B): F[A] => F[B] } case class Foo[X,…
7
votes
2 answers

What is a kind projector

I've been digging into FP and everything that surrounds it, and I found the concept of kind projector written somewhere, without details nor explanations. The only thing I found was this github project, and I'm starting to think if it was referring…
6
votes
1 answer

Understanding Type Projection

Taken from typelevel/kind-projector, what's the distinction between: // partially-applied type named "IntOrA" type IntOrA[A] = Either[Int, A] and // type projection implementing the same type anonymously (without a name). ({type L[A] = Either[Int,…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
5
votes
2 answers

Kind compiler plugin λ not found

I have enabled the kind compiler plugin addCompilerPlugin("org.spire-math" % "kind-projector" % "0.9.6") and I can now use the ? symbol e.g. Map[String, ?] however Lambda and λ are not resolved. val f: Id ~> Future = λ[Id ~> Future](...) produces…
user404345
3
votes
1 answer

Difference between * (star) and _ (underscore) in type parameter

Here someone says that star is underscore from scala 3, but I've seen some code like this in scala 2.13: def make[F[_]: ContextShift: MonadError[*[_], Throwable]: Effect: Logging](): ... Does it have a same meaning and just specify that type in *…
3
votes
1 answer

kind-projector returns strange results

I have these types: SomeTypeClass A higher kinded type which has one type parameter of kind * => * => * trait SomeTypeClass[P[_, _]] { def test[F[_], S, T, A, B](f: (A => F[B]) => S => F[T]) (pab: P[A, B]) …
3
votes
1 answer

scala generic function `not found: type ?`

When I use scala to create a function like this,It told me that not found: type ? scala def save[ K: SpatialComponent: TypeTag, V <: CellGrid: TypeTag: ? => TileMergeMethods[V]: ? => TilePrototypeMethods[V] ](id: LayerId, rdd:…
wsf1990
  • 195
  • 2
  • 12
3
votes
2 answers

How do I translate this type lambda into Kind-Projector syntax?

Given type parameters of F[_] and A[_] how do I turn the following type lambda into the more pleasant Kind-Projector syntax? ({type λ[α] = F[A[α]]})#λ I would have imagined it would be something like F[A[?_]], but the compiler complains about…
Noel M
  • 15,812
  • 8
  • 39
  • 47
3
votes
1 answer

Extend NaturalTransformation of Coproducts

I have F ~> H G ~> H Where ~> is cats.NaturalTransformation. I'm able to construct a λ[A => F[A] :+: G[A] :+: CNil] ~> H Using the kind-projector syntax for readability Here's how I'm doing it def or[G[_]](g: G ~> H): λ[A => F[A] :+: G[A] :+:…
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
3
votes
1 answer

What does λ[α =>F] mean?

I'm learning Scalaz recently. I would like to know how λ[α =>F] works? scala> Applicative[λ[α => Int]].point(10) res45: Int = 0 scala> Applicative[λ[α => String]].point(10) res46: String = "" I can understand λ means some type here, but I could…
Binzi Cao
  • 1,075
  • 5
  • 14
2
votes
1 answer

Polymorphic method works with type lambda, but not with type wildcard in Scala 3

In Scala 3 I can define a functor for state using type lambda: given stateFunctor[S]: Functor[[A] =>> State[S, A]] with override def map[A, B](a: State[S, A])(fx: A => B): State[S, B] = State(a.run.andThen { case (s, a) => (s, fx(a)) }) I…
Andronicus
  • 25,419
  • 17
  • 47
  • 88
2
votes
1 answer

Clarifying cross version behavior in Scala

I wonder what is the difference between the two here: addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.11.3" cross CrossVersion.full) // if your project uses multiple Scala versions, use this for cross…
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
2
votes
1 answer

Generalized constraints within type parameter clause?

SLS specifies syntax of type parameter clause as TypeParamClause ::= ‘[’ VariantTypeParam {‘,’ VariantTypeParam} ‘]’ FunTypeParamClause::= ‘[’ TypeParam {‘,’ TypeParam} ‘]’ VariantTypeParam ::= {Annotation} [‘+’ | ‘-’] TypeParam TypeParam …
Mario Galic
  • 47,285
  • 6
  • 56
  • 98
1
2