-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTTArrow.java
More file actions
45 lines (37 loc) · 1.07 KB
/
Copy pathASTTArrow.java
File metadata and controls
45 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.Set;
public class ASTTArrow implements ASTType {
ASTType dom;
ASTType codom;
public ASTTArrow(ASTType d, ASTType co) {
dom = d;
codom = co;
}
public ASTType getCodom() {
return codom;
}
public ASTType getDom() {
return dom;
}
@Override
public String toStr() {
return "("+dom.toStr()+"->"+codom.toStr()+")";
}
@Override
public boolean eqt(ASTType t)
{
if (t instanceof ASTTArrow) {
ASTTArrow ta = (ASTTArrow)t;
return (codom.eqt(ta.getCodom()) && ta.getDom().eqt(dom));
}
return false;
}
@Override
public boolean subtypeOf(ASTType t, Environment<ASTType> e, Set<String> seen) throws InterpreterError {
t = ASTTypeDef.unfold(t, e);
if (!(t instanceof ASTTArrow other))
return false;
boolean argsMatch = other.getDom().subtypeOf(this.dom, e, seen);
boolean returnMatch = this.codom.subtypeOf(other.getCodom(), e, seen);
return argsMatch && returnMatch;
}
}