Re: Pre-RFC proposal: opt-in implicit interfaces / structural typing
On 7 November 2025 21:34:56 GMT, Larry Garfield <larry@garfieldtech.com> wrote:
>__toString() is *old*. It may go all the way back to 5.0, but it was there at least as of 5.2.
>The problem is that there was no way to type against it.
I know all that. I've just never understood why you would *want* to type against it. The only
thing you can do with that knowledge is turn the object into a string, so why not just ask for a
string in the first place?
But I apologise for drifting off topic; the relevant point is that it works exactly how the proposed
implicit interfaces would, so whatever reasoning was used for it might serve a useful example for
other potential uses. If nothing else, being able to say "it's a built-in implicit
interface" would be less confusing than explaining it as a magical special case.
Who knows, maybe there are people wishing they could type against other magic methods, who could do
so by declaring their own implicit interfaces.
As I say, I'm personally much more interested in highly explicit code, so am more likely to go
completely the opposite direction: use an *empty interface*, where the only thing you're doing
is "tagging" a class as intended for a particular purpose.
But, I know there are people who like "duck typing", and implicit interfaces or structural
typing give a way to formalise that, so I can see value for those people.
Rowan Tommins
[IMSoP]
Thread (12 messages)