Torturing Rustc by Emulating HKTs

Dev pokes Rust’s brain to fake type magic — fans cheer, skeptics clutch pearls

TLDR: A Rust blogger tried to fake “types that take types,” intentionally tripping the compiler and sparking big feelings. Readers split between excitement for powerful new type tricks and fears of added complexity, swapping war stories and memes while debating whether Rust should chase this feature or keep things simple.

One Rust dev tried to fake “types that take other types” — a brain‑bendy trick called higher‑kinded types — and managed to confuse the Rust compiler on purpose. The post is half math class, half magic show, with jokes about logic proofs and a detour into another proof tool. The crowd? Split and loud. Some were dazzled (“incredible,” said cptroot) but admitted the math went over their heads. Others clutched their keyboards at the sight of an intentional crash, asking if this is brilliant exploration or needless chaos. The big mood: fascination mixed with “please don’t summon the compiler demon.”

Commenters piled on with war stories. j‑krieger confessed they “hit a funny compiler end‑of‑the road” trying to use cutting‑edge features that compute numbers at compile time, proving we all love breaking stuff until it breaks back. Meanwhile, mmastrac waved an experimental crate — tuplemagic — arguing this “type mapping” power is real, just awkward to write. That lit the fuse: Team Give Us Fancy Types Now vs Team Keep Rust Simple and Fast. Memes flew (“1 + 1 = compiler panic”), someone called it “Rust speedrunning a logic textbook,” and a few begged the language team to add the feature… or never, depending which comment you read.

Key Points

  • The author designs a calculator AST and introduces metadata wrappers to optionally include source spans.
  • To generalize metadata, a Wrapper<T, M> is defined, with type aliases for spanned and simple variants.
  • Parametrizing AST nodes over a generic wrapper W requires higher‑kinded types (type constructors).
  • Rust currently lacks direct support for HKTs, preventing abstraction over a type constructor like W<T>.
  • A compile error with Vec lacking a type parameter illustrates that generic identifiers are not complete types in Rust.

Hottest takes

“incredible, even as it rapidly outpaced my PL and mathematics knowledge” — cptroot
“hit a funny compiler end-of-the road” — j-krieger
“map, filter and reduce types is insanely powerful” — mmastrac
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.