Challenge 2: A Custom Describable Typeclass — Possible Solution ==================================================================== Main.hs: class Describable a where describe :: a -> String instance Describable Int where describe n = "the integer " ++ show n instance Describable Bool where describe True = "a true value" describe False = "a false value" main :: IO () main = do putStrLn (describe (42 :: Int)) putStrLn (describe True) Output: the integer 42 a true value Explanation: Describable declares one capability, describe, with no implementation of its own -- just a type signature. Each instance (Int and Bool) supplies its own genuinely different describe body: Int's version formats the number, Bool's version pattern-matches on True/False directly. Both are called with the exact same function name, describe, with GHC dispatching to the correct implementation based on the argument's actual type -- exactly the ad-hoc polymorphism the chapter describes. WHY THIS WORKS AS AN ANSWER ------------------------------ This defines a genuine custom typeclass with two real instances for different types, each with a distinct implementation, calling both through the same shared function name to demonstrate ad-hoc polymorphism directly.