LambdaTerm toString

This commit is contained in:
Arne Keller 2021-02-01 15:11:19 +01:00
parent 07f16ed2d0
commit 2d92294736
6 changed files with 26 additions and 3 deletions

View File

@ -63,6 +63,11 @@ public class AbsTerm extends LambdaTerm {
return termVisitorTree.visit(this, assumptions, type);
}
@Override
public String toString() {
return "λ" + var + "." + body;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@ -59,6 +59,11 @@ public class AppTerm extends LambdaTerm {
return termVisitorTree.visit(this, assumptions, type);
}
@Override
public String toString() {
return "(" + left + ")(" + right + ")";
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@ -74,6 +74,11 @@ public class LetTerm extends LambdaTerm {
return body;
}
@Override
public String toString() {
return "let " + variable + " = " + definition + " in " + body;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@ -48,6 +48,11 @@ public class VarTerm extends LambdaTerm {
return visitor.visit(this, assumptions, type);
}
@Override
public String toString() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@ -42,7 +42,6 @@ public class MainViewImpl extends AppLayout implements MainView {
MainViewListener presenter = new Presenter(new ModelImpl(), this);
addToNavbar(true, new UpperBar(presenter));
addToDrawer(new DrawerContent());
}
@Override

View File

@ -24,16 +24,20 @@ class LambdaParserTest {
@Test
void absTerm() {
LambdaParser parser = new LambdaParser("λx.x");
assertEquals(new AbsTerm(new VarTerm("x"), new VarTerm("x")), parser.parse().unwrap());
LambdaTerm term = parser.parse().unwrap();
assertEquals(new AbsTerm(new VarTerm("x"), new VarTerm("x")), term);
assertEquals("λx.x", term.toString());
}
@Test
void appTerm() {
LambdaParser parser = new LambdaParser("(λx.x)(λx.x)");
LambdaTerm term = parser.parse().unwrap();
assertEquals(
new AppTerm(new AbsTerm(new VarTerm("x"), new VarTerm("x")),
new AbsTerm(new VarTerm("x"), new VarTerm("x"))),
parser.parse().unwrap()
term
);
assertEquals("(λx.x)(λx.x)", term.toString());
}
@Test
void letTerm() {