-
Notifications
You must be signed in to change notification settings - Fork 18
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
Illegal .. notation for constructor LogOutView. The constructor has no labeled field #15
Comments
Good point. Can I suggest a different phrasing of the message?
Note that this error message can arise even if the constructor has fields -- as long as they aren't record fields. In the first "possible fix", the suggested replacement would have dummy variables (or maybe blanks?) for each field of the constructor. What do we think? |
Perhaps this should just be legal? An empty data type has not "committed" to having fields that are only positional. FWIW this is how rust does it, with: struct Foo;
struct Foo();
struct Foo {} all meaning the same thing. |
I don't think #15 (comment) is quite relevant for this ticket -- this ticket is about a pattern-match, while that comment looks like it is about structure declarations. Regardless, this repo is all (and only!) about error messages, not about changing the language, which is discussed elsewhere. |
Well my point is that as a new user, data Foo = Foo { a :: Int }
f (Foo {..}) = 1 being allowed, but data Foo = Foo { }
f (Foo {..}) = 1 not being allowed, feels arbitrary and annoying. A big message from functional programming is that "base cases are not edge cases", e.g. when teaching structural recursion. GHC special casing for the "empty record" for no good reason feels like a betrayal of the principles Haskell is supposed to espouse. I am happy to open an issue elsewhere, but I do think it is perfectly natural for auditing error messages to lead us to question language decisions. If there isn't in fact a problem, the best error message is none at all! |
Separately, while testing this out, I realized the "no fields" error message supersedes the " |
I opened language-change issue in ghc-proposals/ghc-proposals#484 |
If the proposal doesn't go through, the error message should at least point out |
OK. To my own surprise, I'm actually convinced here that the GHC proposal is a better fix than any rewording for the empty-constructor case. Thanks for opening that! But the error message phrasing still could be improved for the non-empty case:
This is accepted. But
is rejected with the error message at the top of this ticket:
And I still think that a message such as #15 (comment) would be a nice improvement. |
:) Glad it was persuasive! I will try to make it into an actual proposal soon. I agree it still needs a reword.
If we are to accept the proposal, I might further tweak your suggestion as
or
since "have named record fields" to me implies there must be at least one (named) field. |
Fair point. Except that I don't want to say "record constructor" because Here is the full message for consideration:
where the number of |
Perfect! Yes "record structure" has those problem, but my first one felt a bit too verbose. "has unnamed fields" avoids both pitfalls! |
This has been fixed via ghc-proposals/ghc-proposals#496 |
@mpscholten that proposal doesn't seem to be implemented yet. I think we should keep issues here open until the improvements have actually been incorporated in a released version of GHC. |
Hey all! I'm the one implementing ghc-proposals/ghc-proposals#496. Since you are somewhat invested in error messages and in this one in particular already, I would appreciate it if you gave your opinion(s) regarding what the error message should be in the case that Here's the relevant part of the patch. |
Given this code:
GHC errors with:
A better error message would be:
(Taken from https://github.com/digitallyinduced/haskell-ux)
The text was updated successfully, but these errors were encountered: