Type and LetTerm are now abstract classes again

This commit is contained in:
uogau 2021-03-11 13:11:33 +01:00
parent 4e56c69833
commit 26caed074d
10 changed files with 23 additions and 23 deletions

View File

@ -12,7 +12,7 @@ import java.util.Set;
/**
* Representation of an abstraction term with its two sub-lambda terms.
*/
public class AbsTerm implements LambdaTerm {
public class AbsTerm extends LambdaTerm {
private final VarTerm var;
private final LambdaTerm body;

View File

@ -9,7 +9,7 @@ import java.util.*;
/**
* Representation of an application term consisting of a function and the parameter passed to it.
*/
public class AppTerm implements LambdaTerm {
public class AppTerm extends LambdaTerm {
private final LambdaTerm left;
private final LambdaTerm right;

View File

@ -12,7 +12,7 @@ import java.util.Set;
/**
* Abstract representation of a constant lambda term that has a predetermined type and a value of that type.
*/
public abstract class ConstTerm implements LambdaTerm {
public abstract class ConstTerm extends LambdaTerm {
/**
* Returns the named type of the constant

View File

@ -12,27 +12,27 @@ import java.util.Set;
* Depending on the subclass used, a lambda term may contain several other lambda terms
* and thus form a tree-like structure of lambda terms.
*/
public interface LambdaTerm {
public abstract class LambdaTerm {
/**
* Returns whether the lambda term contains a let expression
*
* @return whether the lambda term contains a let expression
*/
boolean hasLet();
public abstract boolean hasLet();
/**
* Returns a set of all free variables occurring in the lambda term.
*
* @return all free variables
*/
Set<VarTerm> getFreeVariables();
public abstract Set<VarTerm> getFreeVariables();
/**
* Calls exactly one method on the visitor depending on the lambda term type.
*
* @param termVisitor a visitor
*/
void accept(TermVisitor termVisitor);
public abstract void accept(TermVisitor termVisitor);
/**
* Uses exactly one method of the visitor and provides the arguments passed.
@ -42,6 +42,6 @@ import java.util.Set;
* @param type a type
* @return the result returned by the visitor
*/
InferenceStep accept(TermVisitorTree termVisitorTree,
public abstract InferenceStep accept(TermVisitorTree termVisitorTree,
Map<VarTerm, TypeAbstraction> assumptions, Type type);
}

View File

@ -13,7 +13,7 @@ import java.util.Set;
* Representation of a let term with its variable, the lambda term assigned
* to this variable and the lambda term the variable is used in.
*/
public class LetTerm implements LambdaTerm {
public class LetTerm extends LambdaTerm {
private final VarTerm variable;
private final LambdaTerm definition;
private final LambdaTerm body;

View File

@ -9,7 +9,7 @@ import java.util.*;
/**
* Representation of a variable term with its name.
*/
public class VarTerm implements LambdaTerm {
public class VarTerm extends LambdaTerm {
private final String name;
/**

View File

@ -10,7 +10,7 @@ import java.util.Set;
/**
* Models the type of an abstraction/function.
*/
public class FunctionType implements Type {
public class FunctionType extends Type {
private final Type parameter;
private final Type output;

View File

@ -10,7 +10,7 @@ import java.util.Set;
/**
* Models a simple named type.
*/
public class NamedType implements Type {
public class NamedType extends Type {
/**
* boolean type
*/

View File

@ -9,21 +9,21 @@ import java.util.Set;
/**
* Models the type of a lambda term.
*/
public interface Type {
public abstract class Type {
/**
* Checks whether some type occurs in this type.
*
* @param x the type to look for
* @return whether the specified type occurs in this type
*/
boolean contains(Type x);
public abstract boolean contains(Type x);
/**
* Returns a set of all free type variables occurring in the type.
*
* @return all free type variables
*/
Set<TypeVariable> getFreeTypeVariables();
public abstract Set<TypeVariable> getFreeTypeVariables();
/**
* Substitutes a type Variable for a different type.
@ -32,7 +32,7 @@ public interface Type {
* @param b the type to insert
* @return a Type that is created by replacing a with b
*/
Type substitute(TypeVariable a, Type b);
public abstract Type substitute(TypeVariable a, Type b);
/**
* Applies the given substitution to the type.
@ -40,7 +40,7 @@ public interface Type {
* @param substitution the substitution to apply to the type
* @return the substituted type
*/
default Type substitute(Substitution substitution) {
public Type substitute(Substitution substitution) {
return substitute(substitution.getVariable(), substitution.getType());
}
@ -49,7 +49,7 @@ public interface Type {
*
* @param typeVisitor the visitor that wants to visit this
*/
void accept(TypeVisitor typeVisitor);
public abstract void accept(TypeVisitor typeVisitor);
/**
* Computes the necessary constraints (and substitution) to unify this type with
@ -58,7 +58,7 @@ public interface Type {
* @param type the other type
* @return unification steps necessary, or an error if that is impossible
*/
Result<UnificationActions, UnificationError> constrainEqualTo(Type type);
public abstract Result<UnificationActions, UnificationError> constrainEqualTo(Type type);
/**
* Computes the necessary constraints (and substitution) to unify this type with a
@ -67,7 +67,7 @@ public interface Type {
* @param type the function type
* @return unification steps necessary, or an error if that is impossible
*/
Result<UnificationActions, UnificationError> constrainEqualToFunction(FunctionType type);
public abstract Result<UnificationActions, UnificationError> constrainEqualToFunction(FunctionType type);
/**
* Computes the necessary constraints (and substitution) to unify this type with a
@ -76,7 +76,7 @@ public interface Type {
* @param type the named type
* @return unification steps necessary, or an error if that is impossible
*/
Result<UnificationActions, UnificationError> constrainEqualToNamedType(NamedType type);
public abstract Result<UnificationActions, UnificationError> constrainEqualToNamedType(NamedType type);
/**
* Computes the necessary constraints (and substitution) to unify this type with a
@ -85,5 +85,5 @@ public interface Type {
* @param type the type variable
* @return the unification steps necessary, or an error if that is impossible
*/
Result<UnificationActions, UnificationError> constrainEqualToVariable(TypeVariable type);
public abstract Result<UnificationActions, UnificationError> constrainEqualToVariable(TypeVariable type);
}

View File

@ -8,7 +8,7 @@ import java.util.*;
/**
* Models a type variable
*/
public class TypeVariable implements Type, Comparable<TypeVariable> {
public class TypeVariable extends Type implements Comparable<TypeVariable> {
private final TypeVariableKind kind;
private final int index;