-
Notifications
You must be signed in to change notification settings - Fork 465
@unboxed fails if a constructor has more than one argument #6272
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
Comments
Also, if I add another constructor to the first definition above: @unboxed
type t = Tuple(int, string) | Float(float) the error turns into
which is clearly incorrect since this does work: @unboxed
type t = Float(float) | String(string) |
And if I add another constructor to the second definition above: @unboxed
type t = Tuple((float, string)) | Float(float) the error now becomes:
which I have no idea what's even supposed to mean. |
That's a different type that's why it works. |
Closing this optimistically. |
The second error message seems plain wrong. If the first case is intentionally unsupported, then it should emit the first error message in the second case as well. I don't know if the second error message should ever be emitted. In the third case I don't understand the error message, or why it would error at all. If I understood that, I could perhaps suggest a better error message. |
I guess this would also be confusing? The analogous OCaml example will give an analogous error. |
No, I think it's clear that those are different. What I find confusing about the reported issue is that it's clearly possible to represent a constructor with multiple arguments as a tuple, because it's possible to represent a constructor with a single argument that is explicitly a tuple. There doesn't seem to be a technical reason (on the surface at least) for not allowing it. But even if this is as designed, the two other errors seem wrong. |
|
From a user perspective, not doing so forces one to deal with unnecessary parentheses. Having the choice of whether or not to include those seems more flexible to me, not less. As a motivating example, what I wanted to do here is to model a GeoJSON position, which can be either 2-dimensional or 3-dimensional. The natural rescript type for this is: type t = LatLng(float, float) | LatLngAlt(float, float, float) But this cannot be type t = LatLng((float, float)) | LatLngAlt((float, float, float)) Because it causes one of the other confusing errors originally reported. It probably wouldn't be able to distinguish between them anyway, and also has these unnecessary and "unnatural" extra parenthesis. Constructors of different arity could on the other hand be distinguished by their arity.
I think the error message is clear enough, although it could be improved by suggesting that it's made an explicit tuple (i.e. |
Leaving open for better error messages / documentation.
There are literal and block cases. Block cases belong to the following categories. Single payload of type
And:
Where Unknown represents: none of the above. The tuple cases ends up in the unknown case as it's none of the above. This won't fit all in one error message, but a combination of better error message and link to documentation on the web site, should clean things up. |
fails with the error:
which is wrong, because it does produce the expected output if I add just a few more parens, making it an explicit tuple which should be equivalent.
The text was updated successfully, but these errors were encountered: