-
Notifications
You must be signed in to change notification settings - Fork 3
/
CLTerms.scala
53 lines (44 loc) · 1.36 KB
/
CLTerms.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package object cl {
sealed trait Term {
def *(that: Term) = cl.*(this, that)
// Given a term M and variable x, M.extract(x) returns a term
// without x, M', s.t. (M' * x) evaluates the same way as M
def extract(x: Var): Term = this match {
case a: Atom if a != x => K * a
case a: Atom if a == x => I
case l * r => S * l.extract(x) * r.extract(x)
}
def contains(x: Var): Boolean = ???
}
case class *(left: Term, right: Term) extends Term {
override def toString = this match {
case p * (q * r) => s"$p(${q * r})"
case _ => s"$left$right"
}
}
def eval(t: Term): Term = ???
def bracketAbstraction(f: Term => Term): Term = {
val x = Var("variable")
f(x).extract(x)
}
def bracketAbstraction(f: (Term, Term) => Term): Term = {
val x = Var("variable-x")
val y = Var("variable-y")
f(x, y).extract(y).extract(x)
}
sealed trait Atom extends Term
sealed trait Const extends Atom
case object S extends Const
case object K extends Const
case object I extends Const
case object B extends Const
case object C extends Const
case object W extends Const
case object Bp extends Const
case object Cp extends Const
case object Sp extends Const
case class Var(name: String) extends Atom {
override def toString = name
}
implicit def symbolToVar(s: Symbol) = new Var(s.name)
}