Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 807
Mike Izbicki Avatar asked Oct 02 '12 19:10

Mike Izbicki


1 Answers

Since it sounds like no one else has a library, I've converted what I've done into a separate project called ConstraintKinds and uploaded it to github. It's extremely simple at the moment and probably doesn't cover any one else's use case yet, but feel free to make your own changes or submit requests.

I will probably wait for more feedback on if this is a good direction before uploading the project to hackage.

like image 62
Mike Izbicki Avatar answered Nov 06 '22 02:11

Mike Izbicki