Suppose that I have this type family that throws a custom type error during compile time if the type passed to it is not a record:
type family IsRecord (a :: Type) where
...
Now I have this type class that has methods with default implementations, but requires that the type is a record, by adding the IsRecord
constraint:
class IsRecord a => Foo a where
foo :: Text
foo = "foo"
When trying to use it incorrectly, if we use it as a regular instance with a type that is not a record, it successfully fails to compile:
data Bar = Bar
instance Foo Bar -- error: Bar is not a record
But if I enable -XDeriveAnyClass
and add it to the deriving clause, this doesn't fail to compile, ignoring completely the constraint:
data Bar = Bar
deriving (Foo)
I understand that DeriveAnyClass
generates an empty instance declaration, which is what I'm doing on the first example, but still it doesn't throw the error. What's going on?
I'm using GHC 8.6.4