Hacker News new | ask | show | jobs
by neolog 1921 days ago
Explicitly declaring which types provide which interfaces is the whole point of explicit interfaces.

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.
1 comments

Right - so if you're introducing type annotations into an existing project and have a method expecting some interface, used by many call-sites spread across various parts of the project, then you can go around wrapping the original type at each call-site as you've indicated.

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.