Advertisement
Guest User

Product Category

a guest
Sep 8th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE TypeFamilies, ConstraintKinds, GADTs, ScopedTypeVariables #-}
  2. module CCC where
  3. import GHC.Exts (Constraint)
  4.  
  5. data Uncurried x y where
  6.   Uncurried :: (a -> c) -> (b -> d) -> Uncurried (a,b) (c,d)
  7.  
  8. data IsPairPf a where IsPairPf :: IsPairPf (x,y)
  9.  
  10. class IsPair a where
  11.     isPairPf :: IsPairPf a
  12.  
  13. class RCat cat where
  14.     type CatElt cat a :: Constraint
  15.  
  16.     cid :: CatElt cat a => cat a a
  17.     (!) :: (CatElt cat a, CatElt cat b, CatElt cat c) => cat b c -> cat a b -> cat a c
  18.  
  19. idUncurried :: IsPairPf a -> Uncurried a a
  20. idUncurried IsPairPf = Uncurried id id
  21.  
  22. compUncurried :: Uncurried b c -> Uncurried a b -> Uncurried a c
  23. compUncurried (Uncurried f1 f2) (Uncurried g1 g2) = Uncurried (f1 . g1) (f2 . g2)
  24.  
  25. instance RCat Uncurried where
  26.     type CatElt Uncurried a  = IsPair a
  27.     cid = idUncurried isPairPf
  28.     (!) = compUncurried
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement