Challenge 2: A Shape3D Typeclass Requiring Shape as a Superclass — Possible Solution ==================================================================== Main.hs: class Shape a where area :: a -> Double perimeter :: a -> Double class Shape a => Shape3D a where volume :: a -> Double data Cube = Cube Double instance Shape Cube where area (Cube s) = 6 * s * s -- surface area perimeter (Cube s) = 12 * s -- total edge length instance Shape3D Cube where volume (Cube s) = s * s * s main :: IO () main = do let c = Cube 3 print (area c) print (volume c) Output: 54.0 27.0 Explanation: `class Shape a => Shape3D a` means any type with a Shape3D instance must ALSO have a Shape instance -- the constraint is checked at compile time, the same way haskell2-2's own Applicative required Functor. Cube genuinely provides both instances, so both area (inherited from the Shape requirement) and volume (Shape3D's own method) can be called on the same Cube value. WHY THIS WORKS AS AN ANSWER ------------------------------ This builds a real superclass-constrained typeclass hierarchy exactly as the chapter introduces, with a single type (Cube) satisfying both the base and the derived typeclass, and both methods called successfully on it.