Challenge 3: An Unreachable Base Case, and Its Fix — Possible Solution ==================================================================== Broken attempt — Main.hs: countdown :: Int -> [Int] countdown 0 = [0] -- base case: exactly 0 countdown n = n : countdown (n - 2) -- recursive case: step down by 2 main :: IO () main = print (countdown 7) -- 7 is ODD -- this never terminates -- Why it never terminates for odd starting values: -- Starting from 7, the recursive case subtracts 2 each time: -- 7, 5, 3, 1, -1, -3, -5, ... The sequence steps straight past 0 -- without ever landing on it exactly, since 7 is odd and every step -- changes the value by an even amount (2). The base case `countdown 0 -- = [0]` can only ever match when the argument is EXACTLY 0 -- it -- will keep recursing through negative odd numbers forever, since no -- pattern in the function matches anything except precisely 0. -- (In practice this typically overflows the stack or runs -- indefinitely rather than "hanging" silently.) Fixed — Main.hs: countdown :: Int -> [Int] countdown n | n <= 0 = [n] -- base case: catches 0 AND any overshoot below it | otherwise = n : countdown (n - 2) main :: IO () main = print (countdown 7) Output: [7,5,3,1,-1] Explanation: Replacing the exact-match base case `countdown 0 = [0]` with a guard `n <= 0` fixes the real problem: instead of requiring the value to land on EXACTLY 0, the base case now fires for 0 or anything that has already stepped past it, catching every possible input regardless of whether the starting value was even or odd. This is the direct Haskell-flavored version of the missing/unreachable base case the chapter's warn-box describes -- the fix isn't about looping differently, it's about making sure the exit condition can actually be satisfied for every input, not just some of them. WHY THIS WORKS AS AN ANSWER ------------------------------ This constructs a genuine unreachable-base-case scenario (odd inputs skip over an exact-match base case of 0), explains precisely why it never terminates, and fixes it with a guard that catches the base case as a range rather than a single exact value.