-
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
c9a3b7b
commit 29f2aad
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
catculator-core/src/main/scala/pl/writeonly/catculator/core/calculators/lazyk/ADT.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,32 @@ | ||
package pl.writeonly.catculator.core.calculators.lazyk | ||
|
||
import pl.writeonly.catculator.core.adt.calculus.Combinator | ||
import pl.writeonly.catculator.core.adt.calculus.Combinator.CombinatorBT | ||
import pl.writeonly.catculator.core.adt.tree.BinaryTree | ||
import pl.writeonly.catculator.core.adt.tree.BinaryTree._ | ||
|
||
import pl.writeonly.catculator.core.adt.calculus.Constants | ||
|
||
import spire.math.Natural | ||
|
||
enum ADT: | ||
case Com(c: Combinator) | ||
case Num(n: Natural) | ||
case Succ() | ||
|
||
object ADT { | ||
|
||
type ADTBT = BinaryTree[ADT] | ||
|
||
val number0: ADTBT = Leaf(ADT.Num(Natural(0))) | ||
val trueVar: ADTBT = fromCombinatorBT(Constants.trueCom) | ||
val falseVar: ADTBT = fromCombinatorBT(Constants.falseCom) | ||
|
||
def fromCombinatorBT(c: CombinatorBT): ADTBT = c match { | ||
case Node(a, b) => Node(fromCombinatorBT(a), fromCombinatorBT(b)) | ||
case Leaf(a) => Leaf(fromCombinator(a)) | ||
} | ||
|
||
private def fromCombinator(c: Combinator): ADT = ADT.Com(c) | ||
|
||
} |