Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# Language TypeFamilies, TypeInType , TypeOperators , UndecidableInstances #-}
  2.  
  3. module Compose where
  4.  
  5. import Data.Kind
  6.  
  7. data TyFun :: * -> * -> *
  8.  
  9. type a ~> b = TyFun a b -> *
  10. infixr 0 ~>
  11.  
  12. type family Apply (f :: k1 ~> k2) (x :: k1) :: k2
  13.  
  14. type a @@ b = Apply a b
  15. infixl 9 @@
  16.  
  17. data TyCon2 (tc :: a -> b -> c) (tf :: TyFun a (b ~> c))
  18. data TyCon1 (tc :: a -> b) (tf :: TyFun a b)
  19.  
  20. type instance Apply (TyCon1 tc) a = tc a
  21. type instance Apply (TyCon2 tc) a = TyCon1 (tc a)
  22.  
  23. --
  24.  
  25. data (:.$) :: (b ~> c) ~> (a ~> b) ~> (a ~> c)
  26. type instance Apply (:.$) a = (:.$$) a
  27.  
  28. data (:.$$) :: (b ~> c) -> (a ~> b) ~> (a ~> c)
  29. type instance Apply ((:.$$) a) b = (:.$$$) a b
  30.  
  31. data (:.$$$) :: (b ~> c) -> (a ~> b) -> (a ~> c)
  32. type instance Apply ((:.$$$) a b) x = (:.$$$$) a b x
  33.  
  34. type (:.$$$$) a b x = (:.) a b x
  35.  
  36. type family (:.) (f :: b ~> c) (g :: a ~> b) (x :: a) :: c where
  37.  (:.) f g x = f @@ (g @@ x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement