package types
type term struct {
tilde bool
typ Type
}
func (x *term ) String () string {
switch {
case x == nil :
return "β
"
case x .typ == nil :
return "π€"
case x .tilde :
return "~" + x .typ .String ()
default :
return x .typ .String ()
}
}
func (x *term ) equal (y *term ) bool {
switch {
case x == nil || y == nil :
return x == y
case x .typ == nil || y .typ == nil :
return x .typ == y .typ
}
return x .tilde == y .tilde && Identical (x .typ , y .typ )
}
func (x *term ) union (y *term ) (_ , _ *term ) {
switch {
case x == nil && y == nil :
return nil , nil
case x == nil :
return y , nil
case y == nil :
return x , nil
case x .typ == nil :
return x , nil
case y .typ == nil :
return y , nil
}
if x .disjoint (y ) {
return x , y
}
if x .tilde || !y .tilde {
return x , nil
}
return y , nil
}
func (x *term ) intersect (y *term ) *term {
switch {
case x == nil || y == nil :
return nil
case x .typ == nil :
return y
case y .typ == nil :
return x
}
if x .disjoint (y ) {
return nil
}
if !x .tilde || y .tilde {
return x
}
return y
}
func (x *term ) includes (t Type ) bool {
switch {
case x == nil :
return false
case x .typ == nil :
return true
}
u := t
if x .tilde {
u = under (u )
}
return Identical (x .typ , u )
}
func (x *term ) subsetOf (y *term ) bool {
switch {
case x == nil :
return true
case y == nil :
return false
case y .typ == nil :
return true
case x .typ == nil :
return false
}
if x .disjoint (y ) {
return false
}
return !x .tilde || y .tilde
}
func (x *term ) disjoint (y *term ) bool {
if debug && (x .typ == nil || y .typ == nil ) {
panic ("invalid argument(s)" )
}
ux := x .typ
if y .tilde {
ux = under (ux )
}
uy := y .typ
if x .tilde {
uy = under (uy )
}
return !Identical (ux , uy )
}
The pages are generated with Golds v0.6.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .