This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Product Category

By: a guest on Sep 8th, 2013  |  syntax: Haskell  |  size: 0.85 KB  |  views: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data