top | item 8864851

(no title)

12423gsd | 11 years ago

Are "Traits" basically C++ Concepts?

discuss

order

adrusi|11 years ago

Somewhere between C++ concepts and Haskell typeclasses with a hint of Java interfaces.

But yes, their primary usage is to require that type parameters exhibit a certain set of properties.

nercury|11 years ago

For someone who knows C#, I would explain them as abstract extension methods that can be overriden for specific types.

bjz_|11 years ago

They fill the same role as concepts - ie. bringing type checking to the call site when using parametrized types, rather than using a duck typed approach, which leads to the big template stack traces that you get in C++.

steveklabnik|11 years ago

There are some technical details that make them different, if I recall correctly. But they're kinda similar. They're also close to Haskell's typeclasses.