Show is a Haskell type class that provides show, converting values into String representations. GHCi uses show to display evaluated values. section 5.2.3
Use Show in practical code by:
- Converting a numeric counter to text while recursively numbering lines: show counter ++ ". " ++ line. section 3.1.2
- Deriving Show for custom data types when their field types also have Show instances. section 5.2.3
- Remembering that derived output resembles Haskell source syntax rather than being intended as human-readable presentation. section 5.2.3
- Pairing derived Show with Read when serialized constructor-like strings must be parsed back into values. section 15.3.2
Displaying a custom map
Declare newtype AssocMap k v = AssocMap [(k, v)] deriving (Show). Evaluating insert 'a' "World" (insert 'b' "Hello" empty) can then display as AssocMap [('b',"World"),('a',"Hello")]. section 5.2.3
data FileType = Other | Image | Compressed deriving (Show, Read, Eq)
See Show derived alongside Read and Eq for a custom FileType, enabling constructor-shaped display and parsing. section 15.3.2
