[Feature Request] User-defined generics (type parameters for classes) #160

Open
opened 2025-12-30 01:21:39 +01:00 by adam · 2 comments
Owner

Originally created by @moritztim on GitHub (May 15, 2024).

Type parameters are only allowed in standard library

But why?

Originally created by @moritztim on GitHub (May 15, 2024). > Type parameters are only allowed in standard library _But why?_
Author
Owner

@bioball commented on GitHub (Jun 10, 2024):

Generics add a lot of complexity to the language, and is hard to get right. This is something we would like to add to the language at some point, but I would say that we're not close yet.

For example, one thing to consider is how to implement variance checking. Today, Pkl does not perform subtype checking, and this is not trivial because of type constraints.

We also have some bugs with type parameters in the core language that will need to be fixed before we can start to consider something like this.

@bioball commented on GitHub (Jun 10, 2024): Generics add a lot of complexity to the language, and is hard to get right. This is something we would like to add to the language at some point, but I would say that we're not close yet. For example, one thing to consider is how to implement [variance checking](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)). Today, Pkl does not perform subtype checking, and this is not trivial because of [type constraints](https://pkl-lang.org/main/current/language-reference/index.html#type-constraints). We also have some [bugs with type parameters in the core language](https://github.com/apple/pkl/issues/405) that will need to be fixed before we can start to consider something like this.
Author
Owner

@joshqou commented on GitHub (Dec 13, 2025):

Ran into this limitation myself. Definitely would be an appreciated feature

@joshqou commented on GitHub (Dec 13, 2025): Ran into this limitation myself. Definitely would be an appreciated feature
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#160