Not directly. The class definition cannot be changed without changing the source and recompiling. In the case of classes defined in standard libraries, this will cause multiple code violations, therefore it is not a realistic option.
However, you can wrap the class and add the necessary restrictions,
class Functor f => ShowFunctor f where smap :: (Show a, Show b) => (a -> b) -> fa -> fb smap f = fmap f
and then use this class instead of the original.
But maybe you donβt need an extra class, and for your applications itβs enough to define smap at the top level and just use this instead of fmap ,
smap :: (Functor f, Show a, Show b) => (a -> b) -> fa -> fb smap = fmap
source share