4 ms·
>Mixing up a string for a list of strings, which both satisfy the iterable interface But those are actual valid and useful implementations of the interface, no
by lacyleathers 4y ago
>Mixing up a string for a list of strings, which both satisfy the iterable interface
But those are actual valid and useful implementations of the interface, nominative typing wouldn't save you.
- Smaug123 4y agoReally? Iterating over a string should give you some kind of {char, code point, grapheme cluster} or whatever; iterating over a list of strings should give you a string. Those are not the same type, and any nominative type system should surely realise this.
- lacyleathers 4y agoIf you step outside the generic interface, duck-typing would of course also give you a compiler (or runtime) error. Not sure what scenario you're imagining here.
- Smaug123 4y agoThe scenario I'm imagining here is precisely the parent's example of Python; isn't it one of the absolutely standard mistakes that everyone makes?
- lozenge 4y agoI've never intentionally passed a string to a function that expects a list of strings. But I have done it accidentally very often and received an incorrect return value (instead of an exception). I'm including functions like min() there, technically it can take a string argument, but I've never wanted it to.