April 21, 2026
Bananas, Apples, and Brain Melt
Slava's Monoid Zoo
Emoji math sparks chaos: “Where do the Bs come from?”
TLDR: Slava’s fruit-filled puzzle explains how Swift uses a rewrite algorithm to decide type equality. Commenters were confused about needing bananas to change apples, joked about emoji pain, and some admitted fear of the math, highlighting the gap between compiler power and developer comfort.
Slava’s “Monoid Zoo” drops a brain-bender: a math puzzle with apples and bananas that secretly explains how the Swift compiler decides when two types are the same. The twist? The rules need bananas to turn apples into more apples, but the sample starts with only apples. Cue comment-section meltdown. One reader flatly asked if the answer is just “no,” then confessed emojis won’t even render on their platform, adding, “imagine there’s apples.” Peak internet.
Meanwhile, the math-curious crowd nervously peeked over the fence. One commenter admitted they’re sticking to the “comfy world of commutative monoids” (aka math where order doesn’t matter) while Slava’s puzzle chases apples through non-commutative chaos. Drama brewed between “this is compiler sorcery” and “why do I need bananas to count apples.”
The underlying message: the Swift compiler uses the Knuth–Bendix method (a way to rewrite strings so they settle into a normal form) to tame type relationships, but sometimes the method can run forever. The community? Half fascinated, half frazzled. Jokes popped about a “banana shortage,” “bring-your-own-B,” and the eternal struggle of devs wrestling with math dressed up as fruit. It’s geek theater with 🍎🍌 and just enough existential dread to keep scrolling.
Key Points
- •Swift’s compiler applies the Knuth–Bendix completion algorithm to implement same-type requirements by modeling generic signatures as monoids with relations.
- •The word problem is introduced and exemplified with two relations (bab=aaa, bbb=bb), where transforming a^8 to a^10 is possible in a minimum of 15 steps.
- •The word problem for finitely-presented monoids is undecidable in general; a short undecidable presentation is cited from classic literature.
- •Finite complete rewriting systems provide normal forms that solve the word problem when available; Knuth–Bendix attempts to construct them.
- •Knuth–Bendix can fail to terminate and must fail for undecidable instances; the article hints at questions about decidable cases before trailing off.