2 ms·
Can you clarify why it can't be duck typing if it's static? For instance, in F# you can declare a function that can take any type that provides a specific metho
by MichaelGG 14y ago
Can you clarify why it can't be duck typing if it's static? For instance, in F# you can declare a function that can take any type that provides a specific method name and signature. You can pass any object to such a function as long as it has that method - there's no other similarities required in the types you pass to it. How is that not "duck typing"?
- edmccard 14y agoThere is little difference between "structural typing" in go, where function signatures reference named and separately defined interfaces, and "static duck-typing" in F#, where function signatures using constraints effectively define an anonymous interface right there in the signature. In either case, type errors are detected at compile time. Some people prefer to use "structural typing" for both (maybe using "implicit structural typing" to describe what can be done in F#), and to use "duck typing" to describe languages without type-checking, where type errors only happen at run time. But it's all just terminology.