Skip to content

Commit

Permalink
Add top and bottom type operators (wip).
Browse files Browse the repository at this point in the history
See issue #94.

Still need to:

-   Add them to taxonomy.
-   Handle top and bottom types in transformation graphs.
-   Add tests.
-   Replace wildcards in query types with `Bottom`.
  • Loading branch information
nsbgn committed Jun 16, 2022
1 parent a385181 commit 668e5bc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions transformation_algebra/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ def __call__(self, *params: Type) -> TypeOperation:

def subtype(self, other: TypeOperator, strict: bool = False) -> bool:
assert isinstance(other, TypeOperator)
return ((not strict and self == other) or
bool(self.parent and self.parent.subtype(other)))
return (not strict and self is other) or (
self is Bottom or other is Top or
bool(self.parent and self.parent.subtype(other))
)

def normalize(self) -> TypeInstance:
return self.instance()
Expand Down Expand Up @@ -444,7 +446,7 @@ def match(self, other: TypeInstance, subtype: bool = False,
return a._operator == b._operator or \
(subtype and a._operator.subtype(b._operator))
elif a._operator != b._operator:
return False
return a._operator is Bottom or b._operator is Top
else:
result: Optional[bool] = True
for v, s, t in zip(a._operator.variance, a.params, b.params):
Expand Down Expand Up @@ -948,6 +950,12 @@ def fulfill(self) -> bool:
"The special constructor for the unit type."
Unit = TypeOperator('Unit')

"The bottom type contains no values and is a subtype to everything."
Bottom = TypeOperator('Bottom')

"The top type contains all values and is a supertype to everything."
Top = TypeOperator('Top')

"A wildcard: fresh variable, unrelated to, and matchable with, anything else."
_ = TypeSchema(lambda: TypeVariable(wildcard=True))

Expand Down

0 comments on commit 668e5bc

Please sign in to comment.