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

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