Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

Type argument inference #1

Open
albrow opened this issue Jun 8, 2018 · 1 comment
Open

Type argument inference #1

albrow opened this issue Jun 8, 2018 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@albrow
Copy link
Owner

albrow commented Jun 8, 2018

For now, Fo always requires type arguments and does not support type argument inference. I don't expect that the algorithm for inferring type arguments (at least most of the time) will be very complicated. We can always fallback to requiring type arguments if the type-checker can't infer them. This makes it possible to implement a simpler type argument inference algorithm at first and then improve it over time in a backwards-compatible way.

The tricky bit is that the part of the type-checker which converts an ast.TypeArgExpr into a concrete type is separate from the part that looks at, e.g., the function arguments or rhs of a composite literal that would be required for type inference.

A good place to start is the typeArgsRequired function. Right now it detects cases where a generic type is being used without type parameters and returns an error. Instead we should return a new data structure which represents a generic type that still needs type arguments. Later on, the type-checker will detect, e.g., a function call where the function type is this new data structure. It will then attempt to infer the type arguments based on the function arguments, and if it cannot, return an error similar to the one we return now.

@albrow albrow added the enhancement New feature or request label Jun 8, 2018
@albrow albrow self-assigned this Jun 8, 2018
@albrow albrow changed the title Type inference Type argument inference Jun 8, 2018
@chewxy
Copy link

chewxy commented Jun 13, 2018

If you need help with type inference, I wrote a HM package: https://github.com/chewxy/hm. Happy to help

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants