Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modular calculi #629

Open
loewenheim opened this issue Apr 26, 2017 · 0 comments
Open

Modular calculi #629

loewenheim opened this issue Apr 26, 2017 · 0 comments

Comments

@loewenheim
Copy link
Member

loewenheim commented Apr 26, 2017

I implemented a small strawman proposal for making calculi modular. It works pretty nicely with current dotty (the experimental compiler that will eventually become Scala 3).

import Calculi._

trait Inference


case class Inf1(i: Int) extends Inference
case class Inf2(s: String) extends Inference
case class Inf3(i: Int, j: Int) extends Inference

case class Proof[+C <: Inference](val inf: C, val subProofs: Vector[Proof[C]])

object Calculi {
  type Partial = Inf1 | Inf2
  type Full = Partial | Inf3
  type PartialProof = Proof[Partial]
  type FullProof = Proof[Full]
}

object PartialProof {
  def apply(inf: Partial, subProofs: Vector[Proof[Partial]]): Proof[Partial] = Proof(inf, subProofs)
}

object FullProof {
  def apply(inf: Full, subProofs: Vector[Proof[Full]]): Proof[Full] = Proof(inf, subProofs)
}

object removeInf3 {
  def apply[C <: Inference](proof: Proof[C | Inf3]): Proof[C | Inf1] = proof.inf match {
    case inf: Inf3 =>
      Proof(Inf1(inf.i), proof.subProofs.map(apply))
    case inf: C =>
      Proof(inf, proof.subProofs.map(apply))
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant