# Pre-SIP Higher kinded generics improvements

**URL:** <https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136>\
**Category:** Language Design\
**Created:** [May 29, 2025, 10:37am UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136 "2025-05-29T10:37:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoogeTan](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/googetan/32/3231_2.png) [@GoogeTan](https://contributors.scala-lang.org/u/GoogeTan)\
**Post date:** [May 29, 2025, 10:37am UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136/1 "2025-05-29T10:37:25Z")

</div>

# Summary

This Pre-Sip suggests some improvements for generics and higher kinded types:

- Type partial application
- Curried types

```scala
  case class Bar[F[_]](...)

  def func[F[_, _]] : Bar[F[A, *]]
  def func[F[_][_]] : Bar[F[A]] 

```

## Motivation

As of now it is easy to express a type parameter with one argument set:

```scala
def func[F[_,_]](...) : ...

```

But it cannot be curried even if language has curried types:

```scala
type FCurried = [A] =>> [B] =>> F[A, B]

```

This inconsistency leads to more verbose syntax:

```scala
// Current
def func[F[_, _]] : Bar[[Value] =>> F[A, Value]]
// Proposed
def func[F[_, _]] : Bar[F[A, *]]
// or
def func[F[_][_]] : Bar[F[A]] 

```

An example from cats library:

```scala
def func[F[_], Error](using MonadError[F, Error])(...) : F[A]
// instead of
def func[F[_] : MonadError[*[_], Error], Error](...) : F[A]

```

This significantly decreases code readability.

## Solution

As a solution I suggest these changes:

- Allow many argument sets for generic types:

```scala
case class Bar[F[_]](...)

def func[F[_][_]] : Bar[F[A]] 

```

- Allow partial type application:

```scala
case class Bar[F[_]](...)

def func[F[_, _]] : Bar[F[A, *]] // The same as [Value] =>> F[A, Value] 

```

And some more complex examples

```scala
Foo[*[_]]
Foo[*[+_]]
Foo[*[-_]]
Foo[*[+_, -_]] // same as [Value] =>> Foo[Value] where Foo expects F[+_, -_]
Foo[*[_][_]] // same as [Value] =>> Foo[Value] where Foo expects F[_][_]

```

But it seems that usually compiler will be able to figure kind out itself so I’m not sure the language needs these kind marks.

These improvements will improve code readability and bring types closer to the common values.

---

<div class="post-metadata">

**Author:** ![mberndt](https://contributors.scala-lang.org/letter_avatar_proxy/v4/letter/m/d9b06d/32.png) [@mberndt](https://contributors.scala-lang.org/u/mberndt)\
**Post date:** [May 29, 2025, 2:43pm UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136/2 "2025-05-29T14:43:50Z")

</div>

Given that things like `[A] =>> [B] =>> F[A, B]` already exist, is there any fundamental reason why we can’t define _all_ n-ary type constructors as syntactic sugar for their curried equivalent?

---

<div class="post-metadata">

**Author:** ![GoogeTan](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/googetan/32/3231_2.png) [@GoogeTan](https://contributors.scala-lang.org/u/GoogeTan)\
**Post date:** [May 29, 2025, 7:24pm UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136/3 "2025-05-29T19:24:12Z")

</div>

For now, classes can only have one type parameter list. I think it is because of java interoperability. Anyway scala in general has n-ary things by default.

---

<div class="post-metadata">

**Author:** ![bishabosha](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/bishabosha/32/3101_2.png) [@bishabosha](https://contributors.scala-lang.org/u/bishabosha)\
**Post date:** [May 29, 2025, 7:44pm UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136/4 "2025-05-29T19:44:52Z")

</div>

> [@GoogeTan](#):
>
> ```auto
> case class Bar[F[_]](...)
> 
> def func[F[_][_]] : Bar[F[A]]
> 
> ```

you can do this today:

```scala
//> using options -Xkind-projector

def func[F <: [_] => [_] => Any] : Bar[F[A]]
def func[F[_, _]] : Bar[F[A, *]]

```

---

<div class="post-metadata">

**Author:** ![aepurniet](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/aepurniet/32/1977_2.png) [@aepurniet](https://contributors.scala-lang.org/u/aepurniet)\
**Post date:** [May 29, 2025, 9:08pm UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136/5 "2025-05-29T21:08:19Z")

</div>

Looking at [Wildcard Arguments in Types](https://docs.scala-lang.org/scala3/reference/changed-features/wildcards.html) (Migration Strategy #3), it looks like eventually we should be able to do exactly what you are suggesting using plain syntax.

At that point `bar1` and `bar2` in [Scastie - An interactive playground for Scala.](https://scastie.scala-lang.org/WYiKhQIkSFurLEnMsB7pCQ) should be equivalent.

That page was last updated 2 years ago!

---

<div class="post-metadata">

**Author:** ![Katrix](https://contributors.scala-lang.org/letter_avatar_proxy/v4/letter/k/c6cbf5/32.png) [@Katrix](https://contributors.scala-lang.org/u/Katrix)\
**Post date:** [May 30, 2025, 10:55am UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136/6 "2025-05-30T10:55:32Z")

</div>

That examples compiles fine today if you add `-Xkind-projector:underscores` to the Scalac options.

---

<div class="post-metadata">

**Author:** ![benhutchison](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/benhutchison/32/1542_2.png) [@benhutchison](https://contributors.scala-lang.org/u/benhutchison)\
**Post date:** [May 30, 2025, 9:27pm UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136/7 "2025-05-30T21:27:50Z")

</div>

And here’s the [scastie](https://scastie.scala-lang.org/zAbtj0RJRmqVtgJ2QEkUpQ) to prove it 🙂

While I’m glad that we can opt into this useful capability, why does it need a special flag to enable?

As [noted](https://contributors.scala-lang.org/t/higher-kinded-type-lambda-placeholders-remain-a-rough-edge-of-the-new-given-syntax/6810) in Nov 2024, the documentation on this topic is confusing, outdated, and spread across two pages. So we see pre-SIPs for features that are partly implemented, yet the documentation is lacking, so even motivated programmers with an interest in the topic can’t figure out how the language works.

---

<div class="post-metadata">

**Author:** ![eshu](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/eshu/32/2137_2.png) [@eshu](https://contributors.scala-lang.org/u/eshu)\
**Post date:** [May 31, 2025, 3:15am UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136/8 "2025-05-31T03:15:34Z")

</div>

Probably this is the reason to break with Java…

---

<div class="post-metadata">

**Author:** ![kai](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/kai/32/1733_2.png) [@kai](https://contributors.scala-lang.org/u/kai)\
**Post date:** [June 5, 2025, 7:50am UTC](https://contributors.scala-lang.org/t/pre-sip-higher-kinded-generics-improvements/7136/9 "2025-06-05T07:50:24Z")

</div>

> [@benhutchison](#):
>
> So we see pre-SIPs for features that are partly implemented,

To be fair, we’ll probably need a SIP for type lambda placeholders anyway to make them an official language feature.

> [@benhutchison](#):
>
> While I’m glad that we can opt into this useful capability, why does it need a special flag to enable?

Well, this happened historically, since it was first added just for cross-compiling with Scala 2 code that used kind-projector. Now, it wasn’t supposed to remain that way indefinitely, as you can see by the timelines in the doc pages, but so far it has.
