Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- Can't load the pageby no1guangming
- First I had heard of duck-typing.
https://en.wikipedia.org/wiki/Duck_typing
After reading the page I was left with the question of isn't that dynamic inheritance? The seems like dynamic runtime.
by detourdog - While a well written article, and certainly intellectually interesting, I'm not sure I'd be excited to run across this level of indirection in a codebase if I were debugging an issue.
- Coming from Rust:
Why is does implementation still have a the generic T? Should it not be concrete on i32?
/// i32 forms a sum reducer under 0 and addition const sum_trait = impl(Reducer(i32), struct { pub const empty = 0; pub fn combine(x: T, y: T) T { return x + y; } });
by kooi - I see little to no benefits of introducing such "traits" into a language having duck-typing in templates. It may sometimes improve code readability (slightly), but with more boilerplate code for traits handling in exchange. And the result machine code will be identical to code with no traits at all (with only duck-typing).
C++ is a good example of this. It had duck-typing in templates for decades. Then some sort of trait-like mechanism named concepts has been introduced. The only benefit of them seems to be slightly better error messages if someone misuses a template class/function.
by Panzerschrek - > Definition: a Trait is a compile-time struct which contains related functions over a given type.
There is actually a proposal to make Rust traits desugar behind the scenes to basically this: https://goals.rust-lang.org/2026/dictionary-passing-style-ex...
Rust's creator originally wanted an OCaml-style module system instead of traits (https://graydon2.dreamwidth.org/307291.html), and interest persists today (https://www.boxyuwu.blog/posts/an-incoherent-rust/).