Challenge 3: Rust's dyn Trait/Generic Split vs. Haskell's Uniform Dispatch — Possible Solution ==================================================================== // Rust genuinely offers a programmer TWO distinct, separately-chosen // dispatch mechanisms for the same trait. Writing a generic function // like `fn describe(s: T)` uses STATIC dispatch -- the // compiler generates a separate, specialized version of describe for // every concrete type actually used, resolved entirely at compile // time, with zero runtime lookup cost. Writing `fn describe(s: &dyn // Shape)` instead uses DYNAMIC dispatch -- a real vtable is // constructed at runtime, and the correct method is looked up through // it when called, at some genuine runtime cost, but allowing a single // function to accept genuinely different concrete types through one // shared reference type, decided at runtime rather than compile time. // The Rust programmer explicitly picks one or the other at the point // where the trait is used. // // haskell1-8's own dispatch mechanism, dictionary passing, has no // equivalent split at all. Every typeclass-constrained function call // works the SAME way underneath, regardless of whether the calling // code "feels" more like Rust's generic style or Rust's dyn style -- // GHC secretly passes along a dictionary of the relevant typeclass // methods alongside the call, and that one mechanism handles every // case uniformly. There's no separate keyword or type annotation a // Haskell programmer writes to choose "the fast static version" vs // "the flexible dynamic version" the way Rust requires -- Haskell's // compiler and runtime make that call internally (and modern GHC can, // in many cases, specialize dictionary-passing away entirely through // optimization, blurring the line further), rather than exposing it // as an explicit choice in the source code the way Rust does. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly explains Rust's genuine, explicit two-mechanism split (static generics vs. dyn Trait) and contrasts it with Haskell's own single, uniform dictionary-passing mechanism from haskell1-8, directly addressing the real difference the chapter names rather than treating the two systems as identical.