3 ms·
"Copy" feels weird as name of a type. I translate it into "Copyable (trivially)" internally, is that correct?
by mkesper 11y ago
"Copy" feels weird as name of a type. I translate it into "Copyable (trivially)" internally, is that correct?
- deleted 11y ago[deleted]
- Dewie3 11y agoTraits tend to end up as "-able". Maybe you might as well cut out the Hungarian suffix and elide the "able". I don't know if that is the argument, but that's how I view it.
- Manishearth 11y agoYes, but `Copy` is a trait, not a type. Traits can be used as types but they're ... different.
- madez 11y agoI'm longing for formal definitions of type and trait, to see the exact difference.
- Dewie3 11y agoI've been wondering about the same thing recently too. Meanwhile, there is an article that explains how Haskell typeclasses[1] are implemented, or how they conceptually work: https://www.fpcomplete.com/user/jfischoff/instances-and-dictionaries https://www.fpcomplete.com/user/jfischoff/instances-and-dict... [1] I guess close enough analog to Rust traits.
- Manishearth 11y agoTypes are types. Let's take a type system with generics but no single inheritance. Traits are properties that types can have, like Java interfaces though more powerful. Many traits can be used as types to form a vtable dispatch. For example, Box<Send> uses the trait `Send` here as a type. Objects of type `Send` are "unsized" and must be held behind a pointer (which becomes a fat pointer).
- Dewie3 11y ago> Traits are properties that types can have, like Java interfaces though more powerful. The GP asked about formal definitions. So I think they want something more precise than that.
- Manishearth 11y agoI know, I was just clarifying my original statement :)