"Duck Typing" defined

April 24, 2023

I’ve already introduced the concept of duck typing, but now we have more or less a formal definition:

General interfaces

The quantification “the set of all non-interface types” refers not just to all (non-interface) types declared in the program at hand, but all possible types in all possible programs, and hence is infinite. Similarly, given the set of all non-interface types that implement a particular method, the intersection of the method sets of those types will contain exactly that method, even if all types in the program at hand always pair that method with another method.

Of note, an interface matches all possible types in all possible programs. To re-iterate, there is no explicit syntax to indicate that a type “implements” an interface.

Quotes from The Go Programming Language Specification Version of December 15, 2022


Share this

Direct to your inbox, daily. I respect your privacy .

Unsure? Browse the archive .

Get daily content like this in your inbox!

Subscribe