Replies: 2 comments
-
Hi @sobolevn 👋 I agree that it would be immensely valuable to have something like this. But, off the top of my head, I can't come up with a way to express this using phantom types. I'll elaborate a little bit. Phantom types aren't really compatible with mutable data structures, as they can be thought of as recording a current state in the type system. If the state of the observed structure can change, the type system will not have an accurate depiction of the program state any more. A construct like this would need to understand that applying a certain mutating operation to an instance changes its type, so that after applying Do you have more ideas about how this could be implemented? |
Beta Was this translation helpful? Give feedback.
-
A related note is that, given that we were able to make Edit: not sure about this :) Edit: Seems like PEP 647 will not strictly require narrowing: https://www.python.org/dev/peps/pep-0647/#enforcing-strict-narrowing |
Beta Was this translation helpful? Give feedback.
-
Sometimes I have several layers for
Iterator
calls, which look like this:Sometimes, people can break things unintentionally. For example, imagine that
second
has this line now:Now,
second
will break the chain and produce one value less thanfirst
. Sometimes we want to explicitly disallow that.Is there a way to express this using
phantom-types
? If no, let's consider adding a support for it:Beta Was this translation helpful? Give feedback.
All reactions