C++ Concepts vs Rust Traits vs Haskell Typeclasses vs Swift Protocols
summary
Compares C++20 Concepts, Rust Traits, Haskell Typeclasses, Swift Protocols and D type constraints by implementing two concrete examples: a generic add and a shapes example (circle/rectangle). Discovers two semantic categories: type-constraint model (C++, D) where unconstrained generics already compile, and type-class consent (Rust, Swift, Haskell) where traits/protocols/typeclasses must be added; only C++ and D compile the naive generic add. Measures: implementation speed Swift > D > Rust > Haskell > C++; LOC: Haskell 25 (fewest) … C++ (most). Notes Rust compiler gives exceptionally actionable errors and fixes.
AI-written summary · about
chapters (5)
- 0:00Start
- 24:10Ad Hoc vs Parametric Polymorphism
- 31:42Example #1 Adding Two Integers
- 44:25Type Constraints
- 53:37Example #2 Shapes: Circle & Rectangle








