Can't interfaces do that too? You can just say builtins.set implements the receiver interface.
Can't interfaces do that too? You can just say builtins.set implements the receiver interface.
In Java, you have to explicitly mark a class as conforming to an interface inside the class's declaration. You need to have the source and modify it.
In Haskell, you mark a type as conforming to an interface (called typeclass) by adding functions that operate on its instances and implement the interface's requirements. You can do it anywhere, and write an implementation for an existing type, which is normal practice.
In Python, you cannot easily add interface conformance, but possibly you can make a trivial subclass of the desired class, and mark it as conforming to the desired interface (Protocol), without modifying the source.
But I don't think the "you can declare a protocol after several types already implement it" is any different under explicit vs implicit conformance checking.
I can just say
implementer(IReceiver)(builtins.set)
at any time. There's no temporal restriction on when I can do that.Or add a single type annotations to the method declaring that the parameter satisfies a protocol.
implementer(IReceiver)(builtins.set)
only needs to be written once, not once at each call site. It's telling the global registry that builtins.set implements IReceiver.