Re:Static Duck Typing in Python with Protocols
by nlitened on Tuesday November 23, 2021 @03:12AM
(#29315672)
I don't think this example has anything to do with "stronger typing". A Tuple<Tuple<int, int>, Tuple<int, int>> would have passed the type check just fine the same way, without revealing your error.
[ Parent
| on HN ]
Re:Static Duck Typing in Python with Protocols
by tirpen on Tuesday November 23, 2021 @07:40AM
(#29317100)
> I don't think this example has anything to do with "stronger typing".
I disagree. There are definitely languages where you could easily differentiate between a "length-int" and a "coordinate-int" in the type system, while still representing it as only an int in memory at runtime.
I belive both Haskell and Ada can do this for instance.
Re:Static Duck Typing in Python with Protocols
by dragonwriter on Tuesday November 23, 2021 @12:17PM
(#29320385)
> There are definitely languages where you could easily differentiate between a "length-int" and a "coordinate-int" in the type system
Python, via the shared portion of the type system enforced by the major type checkers, is one of those languages.
The fact that a particular library doesn't choose to do this doesn't mean the type system doesn't fully support it.