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

Bad rejection of some instances of classes with fundeps. (Or misleading error message) #4514

Open
Quelklef opened this issue Oct 27, 2023 · 1 comment

Comments

@Quelklef
Copy link

Description

Attempting to declare a class instance like MyClass SomeDatatype (forall a. OtherThing a) fails with an error message that states:

All types appearing in instance declarations must be of the form T a_1 .. a_n, where each type a_i is of the same form, unless the type is fully determined by other type class arguments via functional dependencies.

This error message makes it sound like amending MyClass with the following fundep will resolve the error, but it does not.

class MyClass a b | a -> b

To Reproduce

Attempt to compile the following

module Main where

data Nil a b = Nil

class C a b | a -> b where
  nil :: Nil a b

instance C String Int where
  nil = Nil

instance C String (forall a. a -> Int) where
  nil = Nil

Expected behavior

The code compiles

Additional context

Not positive this is a bug? Maybe just a misleading error message

PureScript version

0.5.10

@rhendric
Copy link
Member

I remember encountering this myself somewhat recently. The comment in the relevant code says:

If the argument is determined via fundeps then we are less restrictive in
what type is allowed. This is because the type cannot be used to influence
which instance is selected. Currently the only weakened restriction is that
row types are allowed in determined type class arguments.

That ‘currently’ leaves me uncertain whether it would cause problems to weaken this restriction further and allow existential types, constrained types, etc.

If the restriction remains as-is, I agree the error could be clearer about this.

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

2 participants