# Higher-kinded type lambda placeholders remain a "rough edge" of the new given syntax

**URL:** <https://contributors.scala-lang.org/t/higher-kinded-type-lambda-placeholders-remain-a-rough-edge-of-the-new-given-syntax/6810>\
**Category:** Language Design\
**Created:** [November 8, 2024, 10:56am UTC](https://contributors.scala-lang.org/t/higher-kinded-type-lambda-placeholders-remain-a-rough-edge-of-the-new-given-syntax/6810 "2024-11-08T10:56:55Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [November 8, 2024, 10:56am UTC](https://contributors.scala-lang.org/t/higher-kinded-type-lambda-placeholders-remain-a-rough-edge-of-the-new-given-syntax/6810/1 "2024-11-08T10:56:55Z")

</div>

I have been experimenting with the [new `given` syntaxes](https://docs.scala-lang.org/sips/sips/typeclasses-syntax.html) in Scala 3.6.1. Fairly successfully, in that with some effort it’s been possible to migrate an existing codebase onto the new syntax without hitting any showstopper issues 🙂

I notice the new documentation revisions seem to emphasize the use of Context Bound syntax, now enhanced with _aggregation_ and _aliases_ (eg `T: {Eq, Show as s}`).

But there’s one aspect of using context bounds that remains awkward to express even in Scala 3.6, and that is when both:

- The context bounds are capability traits on a higher-kinded effect type (`F[_]`).
- The capability traits also take other type parameters

In this case, one wants to express the context bound as a type with a higher-kinded hole, which the effect type will slot into.

Here’s a real life example, from a [telemetry](https://opentelemetry.io/docs/) generation domain:

```scala
 given [F[_]: {Sync, UUIDGen, [F[_]] =>> Tell[F, SpanLogRecord], [F[_]] =>> Stateful[F, List[SpanLogRecord.BeginSpan]]}] => SpanLog[F]

```

In natural language, this says: Given a effect type F[\_], the `SpanLog[F]` capability requires:

- The `Sync[F]` and `UUIDGen[F]` capabilities (from Cats Effect library)
- The `Tell[F, SpanLogRecord]` capability (from Cats MTL library [1]) which abstracts over the ability to emit `SpanLogRecord`s to an output channel
- The `Stateful[F, List[SpanLogRecord.BeginSpan]]` capability, which abstracts over the ability to get/put a `List[SpanLogRecord.BeginSpan]` to a stateful store

However, you can see that bounds `Sync` and `UUIDGen` can be written gracefully, whereas the subsequent two are verbose… `[F[_]] =>> Tell[F, SpanLogRecord], [F[_]] =>> Stateful[F, List[SpanLogRecord.BeginSpan]]}`… ugh!!

The difference is the latter two also take other type parameters. And so there’s a need to indicate where in the whole type the `F[_]` should fit. Currently this requires a [type lambda](https://docs.scala-lang.org/scala3/reference/new-types/type-lambdas.html).

A more succinct syntax option has been termed a [“higher-kinded type lambda placeholder”](https://docs.scala-lang.org/scala3/guides/migration/plugin-kind-projector.html#rewriting-incompatible-constructs) and unfortunately it remains yet unavailable in Scala 3. This is a sorely missed reversion, relative to the syntactic capabilities we had with [Scala2+KindProjector](https://github.com/typelevel/kind-projector?tab=readme-ov-file#inline-syntax) plugin [2].

With such syntax, in future it might look like:

```scala
 given [F[_]: {Sync, UUIDGen, Tell[_, SpanLogRecord], Stateful[_, List[SpanLogRecord.BeginSpan]]}] => SpanLog[F]

```

Yes please! 😁

PS  
[1] [Cats MTL](https://github.com/typelevel/cats-mtl) defines general capability traits like `Tell` and `Stateful` that are completely agnostic/unrelated to monad-transformers. There’s an [issue to clarify the docs around this oft-misunderstood aspect](https://github.com/typelevel/cats-mtl/issues/516), but someone has been too lazy to fix it yet 😼

[2] I noticed the [Scala 3 documentation “Wildcard Arguments in Types”](https://docs.scala-lang.org/scala3/reference/changed-features/wildcards.html) covering the proposed replacement for Kind Projector is sketchy and slightly inaccurate - it would benefit from a review. I think the correct flag is now `-Xkind-projector:underscores`. It could also include some essential details from the [2 → 3 migration notes](https://docs.scala-lang.org/scala3/guides/migration/plugin-kind-projector.html), which AFAICT are not documented anywhere in the Scala 3 reference. And perhaps mention of which Scala release underscore placeholder syntax will become enabled _without_ needing the `-X` flag.

---

<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:** [November 25, 2024, 11:32am UTC](https://contributors.scala-lang.org/t/higher-kinded-type-lambda-placeholders-remain-a-rough-edge-of-the-new-given-syntax/6810/2 "2024-11-25T11:32:44Z")

</div>

> [@benhutchison](#):
>
> And perhaps mention of which Scala release underscore placeholder syntax will become enabled _without_ needing the `-X` flag.

The original timeline was 3.5 IIRC, but currently it doesn’t seem like there is a timeline for this feature.

---

<div class="post-metadata">

**Author:** ![odersky](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/odersky/32/42_2.png) [@odersky](https://contributors.scala-lang.org/u/odersky)\
**Post date:** [November 25, 2024, 12:16pm UTC](https://contributors.scala-lang.org/t/higher-kinded-type-lambda-placeholders-remain-a-rough-edge-of-the-new-given-syntax/6810/3 "2024-11-25T12:16:49Z")

</div>

I believe someone from the community should take the lead on this and make a PR. Then it could land in the next minor version (3.7). It could also be done in one of the upcoming compiler sprees.
