-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsubstitutables.go
72 lines (61 loc) · 1.37 KB
/
substitutables.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package hm
import "fmt"
// Constraints is a slice of Constraint. Like a Constraint, it is also a Substitutable
type Constraints []Constraint
func (cs Constraints) Apply(sub Subs) Substitutable {
// an optimization
if sub == nil {
return cs
}
if len(cs) == 0 {
return cs
}
logf("Constraints: %d", len(cs))
logf("Applying %v to %v", sub, cs)
for i, c := range cs {
cs[i] = c.Apply(sub).(Constraint)
}
logf("Constraints %v", cs)
return cs
}
func (cs Constraints) FreeTypeVar() TypeVarSet {
var retVal TypeVarSet
for _, v := range cs {
retVal = v.FreeTypeVar().Union(retVal)
}
return retVal
}
func (cs Constraints) Format(state fmt.State, c rune) {
state.Write([]byte("Constraints["))
for i, c := range cs {
if i < len(cs)-1 {
fmt.Fprintf(state, "%v, ", c)
} else {
fmt.Fprintf(state, "%v", c)
}
}
state.Write([]byte{']'})
}
// Types is a slice of Type. Future additions to the methods of this type may be possible
type Types []Type
func (ts Types) Contains(t Type) bool {
for _, T := range ts {
if t.Eq(T) {
return true
}
}
return false
}
// func (ts Types) Apply(sub Subs) Substitutable {
// for i, t := range ts {
// ts[i] = t.Apply(sub).(Type)
// }
// return ts
// }
// func (ts Types) FreeTypeVar() TypeVarSet {
// var retVal TypeVarSet
// for _, v := range ts {
// retVal = v.FreeTypeVar().Union(retVal)
// }
// return retVal
// }