We can use the extension ConstraintKinds to extend the functionality of the base type classes to allow constraints. For example, we can make an unboxed vector a functor:
class Functor f where
type FunctorConstraint f x :: Constraint
type FunctorConstraint f x = ()
fmap :: (FunctorConstraint f a, FunctorConstraint f b) => (a -> b) -> f a -> f b
instance Functor VU.Vector where
type FunctorConstraint VU.Vector x = VU.Unbox x
fmap = VU.map
(See these blog posts for more details).
I have noticed myself implementing a rather large portion of the base library type classes in this new style (basically I want to be able to work interchangeably between unboxed vectors and lists), and am wondering if a library for this already exists that I should use, or if I should flesh mine out and add it to hackage.
Edit: Also, are there plans to add this directly to base? It seems like it shouldn't break anything else just by updating the class definitions directly.