Challenge 3: Why Prolog's Missing Loops Aren't Haskell's Reason — Possible Solution ==================================================================== // haskell1-3 established that Haskell has no loops for a genuinely // STRUCTURAL reason: a for loop's entire mechanism depends on // mutating a counter variable each pass, and Haskell has no mutation // mechanism at all -- there is nothing in the language a for loop // could even be built FROM. Recursion is the only thing left once // mutation is entirely off the table. // // Prolog is different in a real, concrete way: it genuinely DOES have // a mechanism for mutable-feeling state -- the dynamic database, // modified at runtime via assert and retract (covered in full in // Course 2). A Prolog program COULD, in principle, simulate loop-like // counter-incrementing behavior using assert/retract to repeatedly // update a fact representing a counter's "current value." The // mutation itself isn't structurally impossible the way it is in // Haskell. // // So why no loops in Prolog either? Because the absence isn't about // mutation being impossible at all -- it's about Prolog's entire // computational model being built around defining RELATIONS and // searching for values that satisfy them, not around describing a // sequence of steps to execute. A traditional loop is shaped to // express "do this thing N times, updating some state along the // way" -- but that's simply not the kind of question Prolog's own // query-and-search model is built to ask. Recursion isn't // compensating for a missing mutation mechanism the way it is in // Haskell; it's the natural, direct way to describe a relation that // holds across a recursively-structured piece of data, which is what // Prolog is fundamentally FOR, independent of whether mutation exists // or not. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly identifies that Prolog's dynamic database genuinely provides a mutation mechanism Haskell lacks entirely, and correctly locates the REAL reason for Prolog's own missing loops in its relational/search computational model rather than in any restriction on mutation, matching the chapter's own central distinction.