Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. -- The following lets you write:
  2. -- ghci> both @All Proxy (Proxy :: Proxy (TyApp Maybe)) Just (1, 'a')
  3. -- (Just 1,Just 'a')
  4.  
  5. {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, TypeFamilies #-}
  6. {-# LANGUAGE RankNTypes, ConstraintKinds #-}
  7.  
  8. import GHC.Exts (Constraint)
  9. import Data.Proxy
  10.  
  11. class fa ~ f a => TyApp f a fa
  12. instance TyApp f a (f a)
  13.  
  14. class All a
  15. instance All a
  16.  
  17. both :: (c a, c b
  18. ,p a r1 -- p is a relation between a and r1
  19. ,p b r2 -- and also a relation between b and r2
  20. )
  21. => Proxy c
  22. -> Proxy p
  23. -> (forall r x. (c x, p x r) => x -> r) -- An input type x and a corresponding
  24. -- result type r are valid iff the p from
  25. -- before is a relation between x and r,
  26. -- where x is an instance of c
  27. -> (a, b)
  28. -> (r1, r2)
  29. both Proxy Proxy f (x, y) = (f x, f y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement