-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29f2aad
commit 6197b6d
Showing
19 changed files
with
154 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
maxColumn = 80 | ||
maxColumn = 160 | ||
version = 3.7.14 | ||
runner.dialect = scala3 | ||
preset = IntelliJ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
catculator-core/src/main/scala/pl/writeonly/catculator/core/calculators/lazyk/Reducer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package pl.writeonly.catculator.core.calculators.lazyk | ||
|
||
import pl.writeonly.catculator.core.adt.calculus.Combinator | ||
import pl.writeonly.catculator.core.adt.calculus.Combinator._ | ||
import pl.writeonly.catculator.core.adt.tree.BinaryTree | ||
import pl.writeonly.catculator.core.adt.tree.BinaryTree._ | ||
import pl.writeonly.catculator.core.calculators.lazyk.ADT._ | ||
import spire.math.Natural | ||
|
||
import scala.util.Right | ||
|
||
object Reducer { | ||
def reduce(f: ADTBT): ADTBTSafe = f match { | ||
case Node(x, y) => applyM(reduce(x), reduce(y)) | ||
case x => Right(x) | ||
} | ||
|
||
def applyM(fM: ADTBTSafe, xM: ADTBTSafe): ADTBTSafe = | ||
for | ||
f <- fM | ||
x <- xM | ||
r <- apply(f, x) | ||
yield r | ||
|
||
def flippedApply(x: ADTBT, y: ADTBT): ADTBTSafe = apply(y, x) | ||
|
||
def apply(f: ADTBT, x: ADTBT): ADTBTSafe = f match { | ||
case Leaf(ADT.Succ()) => succ(x) | ||
case Node(Node(Leaf(ADT.Com(S)), z), y) => applyM(apply(z, x), apply(y, x)) | ||
case Node(Leaf(ADT.Com(K)), y) => Right(y) | ||
case Leaf(ADT.Com(I)) => Right(x) | ||
case _ => Right(Node(f, x)) | ||
} | ||
|
||
|
||
|
||
private def succ(x: ADTBT) = x match { | ||
case Leaf(ADT.Num(x)) => Right(Leaf(ADT.Num(x + Natural.one))) | ||
case _ => Left(s"attempted to apply inc to a non-number $x") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.