On Fri, Jun 7, 2013 at 1:35 AM, Robert Kern <robert.k...@gmail.com> wrote: > On 2013-06-06 10:45, Chris Angelico wrote: > >> For the "accept any object that has a next() method" sorts of rules, I >> don't know of any really viable system that does that usefully. The >> concept of implementing interfaces in Java comes close, but the class >> author has to declare that it's implementing some named interface. In >> theory there could be something that deduces the validity from the >> given structure, but I'm not aware of any language that does this. But >> it would let you do stuff like this (prototyped in Python): > > > As Serhiy notes, Go does this, almost exactly as you wrote it (modulo > syntax). > > http://golang.org/doc/effective_go.html#interfaces_and_types
Thanks (and thanks for actually providing a link). Many years ago I came to the conclusion that anything I could conceive in language design has already been done somewhere :) Anyway, regardless of your language, there's always some criteria that can't be coded. Suppose the valid input for a function were "integers whose square roots are integers but whose cube roots are not". You won't easily get compile-time checking of that. ChrisA -- http://mail.python.org/mailman/listinfo/python-list