A union type, also called a sum type or tagged union, represents one choice from several named alternatives. In Haskell, define the alternatives with data constructors, then pattern match on the selected constructor. section 4.3.1
Listing 4.7 Simple type for distinguishing left from right padding
data PadMode = PadLeft | PadRight
A minimal PadMode type distinguishes left padding from right padding. section 4.3.1
Choosing a padding direction
Use the selected constructor to control the implementation: pad PadLeft 10 "Pad me!" produces " Pad me!", while pad PadRight 10 "Pad me!" produces "Pad me! ". A case expression selects the matching branch. section 4.3.1
Union types provide three practical design benefits:
- Name each permitted alternative explicitly, such as PadLeft and PadRight. section 4.3.1
- Keep alternatives mutually exclusive: one constructor is present at a time. section 4.3.1
- Make each alternative visible to pattern matching and case expressions. section 4.3.1









