-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add iterators and lists #67
Conversation
* Add graph generation code * Rename predicate to TupleSum * Add function to add input node with ports
return transformer.transform(self) or ListType( | ||
self.element_type.transform(transformer) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOI what's the logic here? Try to transform the list and if not just transform the element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if the transformer doesn't specify what to do with a type, we leave the outer type as is and recurse
return self.element_type.linear | ||
|
||
@property | ||
def type_args(self) -> Iterator[GuppyType]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why return Iterator
rather than just Iterable
? (and then avoid the call to iter()
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I think I initially wanted an iterator since I wanted to chain them at some point, but didn't turn out to be necessary.
I created issue #75 for this
guppy/hugr/tys.py
Outdated
if res == TypeBound.Eq: | ||
res = b | ||
if res == TypeBound.Copyable and b == TypeBound.Any: | ||
res = TypeBound.Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could just
res = TypeBound.Any | |
return TypeBound.Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, the following should be enough?
res = TypeBound.Eq
for b in bs:
if b == TypeBound.Any:
return TypeBound.Any
if res == TypeBound.Eq:
res = b
return res
@@ -365,6 +369,155 @@ def __trunc__(self: float) -> float: | |||
... | |||
|
|||
|
|||
@guppy.extend_type(builtins, ListType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference between guppy.type
and guppy.extend_type
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guppy.type
declares a new type, wheras guppy.extend_type
takes an exisisting type and allows users to define new methods on them (similar to extension methods in e.g. C#)
Adds iterators, lists, for loops, and list comprehensions.
This PR sets up the basics:
nodes.py
)ListType
andLinstType
to the Guppy type hierarchy (ingtypes.py
)prelude/builtins.py
)The remaining functionality is added in the following child PRs: