Is there a library that uses ConstraintKinds to generalize all the base type classes to allow constraints?

admin

Administrator
Staff member
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:

Code:
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 <a href="http://blog.omega-prime.co.uk/?p=127" rel="noreferrer">blog</a> <a href="https://dorchard.wordpress.com/2011/10/18/subcategories-in-haskell-exofunctors/" rel="noreferrer">posts</a> 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.

<hr>

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.