Go Programming Experience
Novice
Other Languages Experience
C#, Python, JS
Related Idea
- [ ] Has this idea, or one like it, been proposed before?
- [ ] Does this affect error handling?
- [x] Is this about generics?
- [x] Is this change backward compatible? Breaking the Go 1 compatibility guarantee is a large cost and requires a large benefit
Has this idea, or one like it, been proposed before?
No, not from what i could find
Does this affect error handling?
No
Is this about generics?
Yes
Proposal
Support partial type inference for cases where some type params can't be inferred, for instance:
Foo[,U](5) // in place of Foo[int, U](5)
func Foo[T any, U any](t T) { ... }
Language Spec Changes
No response
Informal Change
No response
Is this change backward compatible?
Yes.
give:
func Foo[T any, U any](t T) { ... }
before the change, calling this function would look like:
Foo[int, U](5)
after the change it could look like:
Foo[,U](5)
Orthogonality: How does this change interact or overlap with existing features?
syntax sugar
Would this change make Go easier or harder to learn, and why?
won't really affect that
Cost Description
No response
Changes to Go ToolChain
No response
Performance Costs
no runtime cost
Prototype
No response
Comment From: gabyhelp
Related Issues
- proposal: spec: partial type inference when only some type params can be inferred #74956 (closed)
- proposal: spec: Allow interfaces to be inferrable generic types #69822 (closed)
- proposal: spec: infer function type parameters from generic interface arguments if necessary #52397 (closed)
- proposal: spec: avoid repeating concrete type parameters when generic arguments are passed to generic functions #53138 (closed)
- proposal: spec: infer types from sufficiently constrained constraints #73527
- spec: add generic programming using type parameters #43651 (closed)
- proposal: spec: support user-defined variance (allow type parameters as type bounds) #67513 (closed)
- spec: type inference should be more lenient about untyped numeric literals #58671 (closed)
- proposal: spec: infer parameter type from arguments in call to result function #64197
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: seankhliao
partial inference is supported, but it has to be from the right most type parameter. I believe this maintains consistency in the language by not allowing employer parameters with just commas