Guest User

Untitled

a guest
Apr 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. object Proofs extends App {
  2. trait Implication[A, B] {
  3. type Out = B
  4. }
  5.  
  6. sealed trait Base
  7. sealed trait Left
  8. extends Base
  9. sealed trait Right
  10. extends Base
  11. case class LeftOne(x: Int, q: Double)
  12. extends Left
  13. case class LeftTwo(y: String)
  14. extends Left
  15. case class RightOne(z: Int)
  16. extends Right
  17. case class RightTwo(q: String)
  18. extends Right
  19.  
  20. object Chirality {
  21. private def evidence[A, B]: Implication[A, B] = new Implication[A, B] {}
  22.  
  23. implicit val left_implies_right_one: Implication[LeftOne, RightOne] = evidence
  24. implicit val left_implies_right_two: Implication[LeftTwo, RightTwo] = evidence
  25. }
  26.  
  27. def map[A, B](a: A)(f: A => B)(implicit ev: Implication[A, B]): ev.Out = f(a)
  28.  
  29. import Chirality._
  30.  
  31. val x = map(LeftTwo("hi mom"))(_ => RightTwo("hi pop"))
  32. println(x.q)
  33. }
Add Comment
Please, Sign In to add comment