3 ms·
> I really feel like in order to get the best of duck typing, you need a good syntax for describing types by usage, not by explicit name. Not sure if this is o
by dom96 10y ago
> I really feel like in order to get the best of duck typing, you need a good syntax for describing types by usage, not by explicit name.
Not sure if this is of interest to you, but the Nim[1] programming language offers a feature that allows you to do exactly what you described. It is called concepts and is documented here: http://nim-lang.org/docs/manual.html#generics-concepts http://nim-lang.org/docs/manual.html#generics-concepts
As a bonus, Nim is also quite Python-like.
1 - http://nim-lang.org http://nim-lang.org
- clusmore 10y agoYep that sounds like what I mean. Haskell typeclasses, Go interfaces, TypeScript interfaces are further examples. Not Java/C# interfaces though, as they need to be declared at design time, and you can't force existing classes to implement interfaces they haven't already declared themselves as implementing.