Skip to content
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

"Data Constructor not in Scope" when defining an operator function starting with : #529

Open
TotallyNotChase opened this issue Oct 6, 2022 · 3 comments

Comments

@TotallyNotChase
Copy link

Defining a function starting with : is invalid according to the parsing rules:

f :< g = f . g

However, the error message here could see some improvement. It currently shows:

error: Not in scope: data constructor ‘:<’

Perhaps it should instead explicitly note that only data constructors may start with colons, and function names must not.

error: Function name may not start with a colon (':')

Or:

error: Only data constructor names may start with a colon (':')

@noughtmare
Copy link

noughtmare commented Oct 6, 2022

One challenge is that this could would compile correctly if you added some definitions above it:

import Preluding hiding (.)

data A = () :< ()

(.) :: a -> b -> A
(.) _ _ = () :< ()

f :< g = f . g

This example is contrived because I didn't try very hard to make it realistic, but this at least shows that the original message isn't always wrong.

I think it is best to add something to the error message like:

error: Not in scope: data constructor ‘:<’
Perhaps you wanted to define an operator, but operator names can't start with a colon ':'

@googleson78
Copy link

Crucially/for example, this can be relied upon in servant-client when you're not using named routes in order to extract a specific function from the functions generated based on an API.

@goldfirere
Copy link
Contributor

I like @noughtmare's suggestion of adding a little informative bit to the error message teaching users about the capitalization rules. (: is a capital symbol, while the others are lowercase, evidently.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants