-
Notifications
You must be signed in to change notification settings - Fork 8
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
Single character class name results in syntax error #2063
Comments
This is not a bug but a consequence of the need to syntactically separate type variable names from classes and protocols. Most languages that implement type inference have a similar rule, with varying flavors. (An extreme case is the language Miranda, whose type variables are limited to the set The motivation comes from the clumsiness that an explicit scoping of type variables would lead to. As an example, consider the type signature of our built-in function
Its generic type can be read a simple pattern that stands for all the concrete instantiations the function actually supports, like
But this assumes we're allowed to quickly identify the placeholders (i.e., the type variables) in the generic pattern above without much analysis. A syntactic rule that says a single upper-case character is always a type variable allows us to do that. But if
Now the full set of names in the current scope would have to be scanned before we can tell what the Of course, if type variables were always explicitly bound one wouldn't have this problem. The signature
is independent of any other definitions of Moreover, if the syntactic separation of type variables were to be removed, one would also have to deal with signatures of the following shape:
Not only are the type variable names extremely ill chosen here, but the mere fact that they are arbitrary names seems to suggest that they carry some other meaning than just being placeholders in a type pattern. Which they still are, even in a language that would allow such syntax. So we have the syntactic separation of type variables for a reason, even though it outrules certain meaningful class names (yes, I've wanted to create small examples with classes
could be considered? Here we use a keyword do indicate that |
I think we should leave the rules as-is. Our current grammar simplifies the compiler. I think we should just document the naming rules so users aren't as surprised. Perhaps expand compiler error messages too... |
Thanks @nordlander for the explanation. In light of this it is clear that just using a slightly longer name for a class is a much simpler solution. But I agree, these rules should be documented in the book. |
Acton Version
0.24.1.20250108.8.28.39
Steps to Reproduce and Observed Behavior
I would like to define a class named with a single character:
The compiler seems to parse the single-character name as a type variable instead:
Expected Behavior
The code compiles!
The text was updated successfully, but these errors were encountered: