I feel that since
StringLike
is a closed type family, there should be a way for GHC to figure out that if only(Show a)
holds,(Pretty a)
is already satisfied
To do that would require type inspection, and would break parameteric polymorphism. Consider defining a type family
type family IsInt a :: Bool where
IsInt Int = True
IsInt a = False
class (b ~ IsInt a) => TestInt a b where
isInt :: a -> Bool
instance TestInt Int True where
isInt _ = True
instance (IsInt a ~ False) => TestInt a False where
isInt _ = False
Now by your argument, GHC should be able to satisfy TestInt a
from ()
. In other words, we should be able to test for any given type whether it is equal to Int. This is clearly impossible.
Similarly, a Show a
dictionary is equivalent to a function a -> ShowS
. How would you be able to decide, given just that, whether the argument is StringLike
?