roc icon indicating copy to clipboard operation
roc copied to clipboard

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

Open Anton-4 opened this issue 1 year ago • 1 comments

# 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

Anton-4 avatar Apr 22 '24 16:04 Anton-4

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

timotree3 avatar Apr 22 '24 16:04 timotree3