Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Proofs extends App {
- trait Implication[A, B] {
- type Out = B
- }
- sealed trait Base
- sealed trait Left
- extends Base
- sealed trait Right
- extends Base
- case class LeftOne(x: Int, q: Double)
- extends Left
- case class LeftTwo(y: String)
- extends Left
- case class RightOne(z: Int)
- extends Right
- case class RightTwo(q: String)
- extends Right
- object Chirality {
- private def evidence[A, B]: Implication[A, B] = new Implication[A, B] {}
- implicit val left_implies_right_one: Implication[LeftOne, RightOne] = evidence
- implicit val left_implies_right_two: Implication[LeftTwo, RightTwo] = evidence
- }
- def map[A, B](a: A)(f: A => B)(implicit ev: Implication[A, B]): ev.Out = f(a)
- import Chirality._
- val x = map(LeftTwo("hi mom"))(_ => RightTwo("hi pop"))
- println(x.q)
- }
Add Comment
Please, Sign In to add comment