Tagged data in Haskell (SICP 2.4.2)
This article presents a Haskell implementation of the tagged-data approach from SICP section 2.4.2, demonstrating how to build a generic arithmetic system using algebraic data types and type classes to dispatch operations based on data type tags like rectangular or polar complex numbers.
Background
SICP (Structure and Interpretation of Computer Programs) is a legendary MIT computer science textbook that uses Lisp to teach fundamental programming concepts. Section 2.4 discusses "tagged data" — attaching type tags to values so that generic operations can dispatch correctly (e.g., adding a complex number and a rational). The author is exploring how to implement this pattern in Haskell, a purely functional, typed language very different from the dynamically-typed Lisp used in SICP. This matters because it highlights the tension between SICP's approach (tagged data with manual dispatch) and Haskell's approach (type classes, which are Haskell's built-in mechanism for ad-hoc polymorphism). The post is part of a broader series adapting SICP ideas to Haskell, which interests Haskell learners and people curious about how classic CS concepts translate across languages.