Pattern matching selects behavior by inspecting a value’s structure, extracting its components, and applying the matching branch. With a typed Shape value, separate Circle and Rectangle cases make each area calculation explicit. section 1.5.2
Calculating a shape’s area
A pattern-matching definition keeps the data cases visible: area (Circle r) = pi * r^2; area (Rectangle w h) = w * h. Calling area with an integer fails at compile time because the function requires Shape, avoiding a debugger-driven failure. section 1.5.2
Pattern matching also handles effectful or optional results. Nested case expressions over Maybe values propagate Nothing explicitly, but the same matching behavior can be hidden inside the Maybe monad and expressed with concise do notation. section 1.5.4
Free interpreters use the same technique recursively: match the Free constructor, descend through its continuation, match each domain constructor, perform its action, and stop at Pure. section 6.3.5











