Challenge 3: Why Querying and Calling Are Fundamentally Different — Possible Solution ==================================================================== // Calling a Haskell function, per haskell1-1's own function-first // model, always produces exactly ONE result (or, for an IO action, // performs exactly one sequence of effects and returns exactly one // value). A Haskell function's type signature -- Int -> Int, for // instance -- promises a single Int comes back for a single Int // going in. There is no built-in language concept of a function call // having "more than one right answer" that the caller might want to // see all of, one at a time. // // Querying a Prolog database is structurally different: a query like // parent(tom, X) isn't asking for "the" value of X -- it's asking // Prolog to search its ENTIRE database for every possible way X could // make the statement true. If the database contains two facts that // both satisfy the query, BOTH are genuinely valid answers, and // Prolog doesn't have to pick just one. Instead, it returns the first // one it finds and pauses, offering the programmer a real choice // (via ;) to ask for the next one, or to stop there. If a query // happens to have zero matching facts, Prolog reports `false.` // instead -- again, not an error, just an honest "no, nothing in the // database makes this true." // // The core difference: a Haskell function call is a computation that // commits to producing one result. A Prolog query is a SEARCH that // may turn up zero, one, or many results, and the language itself is // built around letting the caller ask for more of them on demand, // rather than forcing a single answer to be chosen up front. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly identifies the structural difference the chapter introduces -- a function call commits to one result, a query searches for however many results genuinely exist -- and explicitly addresses the multiple-answer case, including what happens with zero matches, matching the chapter's own framing.