Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types, types2: function type must have no type parameters #67330

Closed
leaxoy opened this issue May 12, 2024 · 3 comments
Closed

go/types, types2: function type must have no type parameters #67330

leaxoy opened this issue May 12, 2024 · 3 comments
Labels

Comments

@leaxoy
Copy link

leaxoy commented May 12, 2024

Proposal Details

Looks at this program:
playground

func x[A, B any](f func(A) B) func[S ~[]A](s S) []B {
	return nil
}

The go compiler raise error: function type must have no type parameters.

This lead to we can't write higher order function which takes type parameter.

In the above example, we can't make the return function take a slice that underlying type is ~[]E.

I don't want to put the type parameters into the declaration of function x, because S depends on the return function, not the function x.

Also declaring it in x forces me to specify the type parameters when calling x instead of deriving them automatically.

@seankhliao
Copy link
Member

The return depends on S, not the other way around.
Plus, type inference works with partial lists.
Please discuss this in the forums.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2024
@atdiar
Copy link

atdiar commented May 12, 2024

Also adding for posterity: higher order generics can very quickly make type checking undecidable, especially when adding branching.

@zigo101
Copy link

zigo101 commented May 13, 2024

What is the problem by writing to

func x[A, B any](f func(A) B) func([]A) []B {
	return nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants