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

Provide an additional reason with the 'cannot derive instance' error #2595

Closed
hdgarrood opened this issue Jan 22, 2017 · 3 comments
Closed

Comments

@hdgarrood
Copy link
Contributor

hdgarrood commented Jan 22, 2017

Currently the following attempts to derive instances all produce a compiler error "cannot derive a type class instance for X" and nothing else:

-- Eq has just one type argument
derive instance eqIntInt :: Eq Int Int

-- missing the wildcard type argument
derive instance genericFoo :: Data.Generic.Rep.Generic Foo

-- cannot derive this class
class Foo
derive instance foo :: Foo

I think it would be nice to provide a little more detail in this error message. Possible reasons the compiler might have failed to derive an instance that I can think of:

  • It's not aware of the class
  • The instance was given the wrong number of type arguments (in particular, I think derive instance genericFoo :: Generic Foo missing the second wildcard might be a common mistake)

It's also possible that we might later add more reasons to this list as the compiler is able to derive more instances.

@garyb
Copy link
Member

garyb commented Jan 22, 2017

Ah yeah, I figured the latter one would be fixed by @LiamGoodacre's recent work on instance arity, but of course it won't here as this is arises during in desugaring and doesn't reach the typechecker.

👍

@hdgarrood
Copy link
Contributor Author

I just noticed #2519. Perhaps these two should be addressed at the same time - maybe this issue subsumes that one, even?

@garyb
Copy link
Member

garyb commented Jan 23, 2017

The errors mentioned in there are caught during typechecking instead of desugaring, but the suggestion is to use a message more like when it fails during desugaring, so I think they are different despite the desired result being the same 😄

@paf31 paf31 self-assigned this Mar 5, 2017
paf31 added a commit that referenced this issue Mar 6, 2017
* Provide an additional reason with the 'cannot derive instance' error, fix #2595

* Clarify error

* Include arity in errors, split out ExpectedTypeConstructor error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants