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

error messages when * is used in annotation but it doesn't make sense #6663

Open
Anton-4 opened this issue Apr 22, 2024 · 1 comment
Open
Labels
error-messages Related to the quality of error messages

Comments

@Anton-4
Copy link
Contributor

Anton-4 commented Apr 22, 2024

# OK. It's a number
three : Int *
three = 3

# OK. It's a function
returnEmpty : {} -> List *
returnEmpty \{} -> []

# Error. It's a list literal
empty : List *
empty = []

# Error. It's a tag
red : [Red, Green, Blue]*
red = Red

# Error. It's a division operation
piApprox : Frac *
piApprox = 22 / 7

Example error message:

-- NUMBER IS NOT POLYMORPHIC --

The type annotation on `piApprox` suggests that it can be used polymorphically:

1 | piApprox : Frac *
2 | piApprox = 22 / 7

Unfortunately, I can't use `piApprox` as any fractional type! I can only use it
as exactly one of `Dec`, `F32`, or `F64`.

If you want me to infer the fractional type that should be used, you can use an
inference annotation instead of `*`:

  piApprox : Frac _

If you explicitly want `piApprox` to be able to be used polymorphically, consider
making it a thunk:

  piApprox : {} -> Frac *
  piApprox = \{} -> 22 / 7
@timotree3
Copy link

Related issue #5536. See Let-generalization: Let’s not? for background on why only syntactic functions and numbers should be allowed to be polymorphic

@lukewilliamboswell lukewilliamboswell added the error-messages Related to the quality of error messages label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-messages Related to the quality of error messages
Projects
None yet
Development

No branches or pull requests

3 participants