Skip to content

Commit

Permalink
Use extension
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-adam committed May 7, 2024
1 parent 7d5a949 commit 10ea23c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ object Combinator {
type CombinatorT = Tree[Combinator]
type CombinatorBT = BinaryTree[Combinator]

def generateT(tree: CombinatorT): String = tree match {
case Tree.Leaf(a) => generateC(a)
case Tree.Node(a) => s"(${a.map(generateT).toList.mkString(" ")})"
}
def generateBT(tree: CombinatorBT): String = tree match {
case BinaryTree.Leaf(a) => generateC(a)
case BinaryTree.Node(a, b) => s"`${generateBT(a)} ${generateBT(b)}"
}
extension (self: CombinatorT)
def generateT: String = self match {
case Tree.Leaf(a) => a.generateC
case Tree.Node(a) => s"(${a.map(_.generateT).toList.mkString(" ")})"
}

def generateC(c: Combinator): String = c.toString
extension (self: CombinatorBT)
def generateBT: String = self match {
case BinaryTree.Leaf(a) => a.generateC
case BinaryTree.Node(a, b) => s"`${a.generateBT} ${b.generateBT}"
}

extension (self: Combinator)
def generateC: String = self.toString
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ enum Sign:
case Minus

object Sign {

def generate(s: Sign): String = s match {
case Plus => "+"
case Minus => "-"
}
extension (self: Sign)
def generate: String = self match {
case Plus => "+"
case Minus => "-"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ enum BinaryTree[+A]:
case Leaf(leaf: A)
case Node(first: BinaryTree[A], follow: BinaryTree[A])

object BinaryTree {
}
object BinaryTree {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import pl.writeonly.catculator.core.adt.tree.BinaryTree.Node

object CombinatorCalculator {

def calculate(c: CombinatorBT) = c match {
def calculate(c: CombinatorBT): Unit = c match {
case Node(f, x) =>
case Leaf(a) =>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class SugarReducer(config: LambdaConfig) {
private def reduceApps(l: NonEmptyList[Lambda]): Lambda =
foldNonEmpty(l)(App.apply)

def reduceLets(ps: NonEmptyList[(String, Lambda)], body: Lambda) = MultiApp(
NonEmptyList(MultiAbs(ps.map(_._1).toList, body), ps.map(_._2).toList),
)
def reduceLets(ps: NonEmptyList[(String, Lambda)], body: Lambda): Lambda =
MultiApp(
NonEmptyList(MultiAbs(ps.map(_._1).toList, body), ps.map(_._2).toList),
)

private def reduceNilList(xs: List[Lambda]): Lambda = xs
.foldRight(config.nilVariable)(config.wrapAppVireoApp)
Expand Down

0 comments on commit 10ea23c

Please sign in to comment.