Concepts vs Typeclasses vs Traits vs Protocols
summary
Compares C++ concepts, Haskell type classes, Rust traits, Swift protocols and D type constraints by actually implementing two exercises: a generic add and a shapes example (circle and rectangle) across five compilers, showing which code compiles as-is and which needs bounds. Demonstrates type constraints vs type classes, notes C++ and D accept unconstrained generics while Rust/Swift/Haskell require explicit bounds, shows C++ needed a custom string concept, reports Swift is fastest to implement and Rust compiler gives precise fix suggestions, and measures LOC and implementation time.
AI-written summary · about
chapters (30)
- 0:00Start
- 5:05Agenda
- 5:34Introduction
- 5:53Introduction to Functional Programming
- 6:47Protocol-Oriented Programming in Swift
- 10:06What Are the Similarities and Differences between C plus Plus and Swift
- 16:12Generics and Parametric Polymorphism
- 16:28Ad Hoc Polymorphism
- 17:02Parametric Polymorphism
- 24:07Swift
- 24:45Haskell
- 26:18Trailing Return Type
- 28:17Generic Functions
- 32:00Type Constraints versus Type Classes
- 32:14Type Constraints
- 35:11Constrained Generics
- 37:26Shapes
- 39:34Rust Example
- 40:35Swift Example
- 44:19Compiler Messages
- 44:53Swift Print Shape Info
- 47:22Write a Type Constraint
- 49:02Rust
- 51:02Haskell Example
- 53:06Conclusions
- 54:19Lines of Code
- 54:56Pleasantness
- 55:33Progressive Disclosure of Complexity
- 58:56Language Rankings
- 59:55Final Thoughts








