PLDB
Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon

Duck Typing

Duck Typing

Duck Typing is a feature.

In duck typing, an object's suitability is determined by the presence of certain methods and properties, rather than the type of the object itself. Duck typing is similar to, but distinct from structural typing. Structural typing is a static typing system that determines type compatibility and equivalence by a type's structure, whereas duck typing is dynamic and determines type compatibility by only that part of a type's structure that is accessed during run time. Protocols and interfaces can provide some of the benefits of duck typing, but duck typing is distinct in that no explicit interface is defined.


Languages with Duck Typing include Python, Ruby, Jule

Example from Jule:
type[T] fn lock_object(obj: T) { obj.lock() }
dispose-blocks-feature.html 路 duck-typing-feature.html 路 first-class-functions-feature.html

View source

PLDB - Build the next great programming language 路 v2022 Day 33 Docs Build Acknowledgements Traffic Today Traffic Trends Mirrors GitHub feedback@pldb.com