error-messages
error-messages copied to clipboard
Not a data constructor clarity
For a module containing only:
data Foo = bar
we get the error message:
error: Not a data constructor: ‘bar’
|
1 | data Foo = bar
|
when compiling or loading into ghci. It came up that this message does not explain why 'bar' is not a valid data constructor, that it does not start with a capital letter or ':'. It would be useful to have that information presented alongside this error message, perhaps with something like:
error: Not a data constructor: ‘bar’
Note: data constructors must begin with a capital letter or ':'
|
1 | data Foo = bar
|
or an equivalent that better matches the style of GHC's other error messages. If adding an additional note would not fit that style, simply changing the message to:
error: Not a valid data constructor: ‘bar’
|
1 | data Foo = bar
|
would help make it more clear that 'bar' cannot be a data constructor and that this is a syntactical issue. I believe there are no other methods of raising this error, but I could see either approach making such cases more confusing if they do exist.
Perhaps something like
<interactive>:1:12: error:
Invalid data constructor: ‘bar’
NB: A data constructor must begin with a capital letter
or be an infix operator beginning with ‘:’
Although on the other hand, perhaps "not a data constructor" might be more helpful in situations where a new user doesn't understand that a data constructor is required in the first place, such as data Option = None | a
.
Side note: is using NB:
in error messages still the way to go, or perhaps a transition to more common language would be preferable (like Note:
mentioned in the OP)?