Instances for ImpredicativeTypes
Now that we have ImpredicativeTypes available in a nice way, it'd be cool if we could use them in type class instances.
Motivation
I'm playing with OverloadedRecordDot
and running into the problem that I can't write a polymorphic virtual method. For example:
data User = User { name :: String }
instance HasField "showWithName" User (forall a . Show a => a -> String) where
getField self a =
concat [self.name, " : ", show a]
What's actually worse is that I can't include any type variables, at all, so I can't even write, like,
instance HasField "identity" User (forall a. a -> a) where
getField _ a =
a
More simply,
Actually, the problem is that we can't write an instance for an impredicative type, at all.
{-# Language ImpredicativeTypes, FlexibleInstances #-}
class C a
instance C (forall a . a -> a)
This fails with the error message:
src/Impl/TH.hs:30:10-30: error:
• Illegal polymorphic type: forall a. a -> a
• In the instance declaration for ‘C (forall a. a -> a)’
|
30 | instance C (forall a . a -> a)
| ^^^^^^^^^^^^^^^^^^^^^
I don't know if this is properly a bug or a feature request - on the one hand, I am asking for new functionality, and on the other hand, I am asking for the intersection of existing functionality to work.