Last Updated: February 14, 2022
· Brian Zeligson

Unary summands for n-ary sums, or m-ary summands for unary sums

Haskell has some hard lines around datatype promotion.

If I declare an n-ary sum type whose constructors are themselves m-ary products, those m-ary products are inextricably linked to the larger sum type in which they are declared over a majority of contexts.

That is to say, for A | B | C, there is no defining a function that takes B | C.

If all m-ary products are defined in unary sums, and n-ary sums carry exclusively unary summands, you get reuse: E.g

data A = A x y z
data B = B d e
data C = C p q r s

data S1 = A1 A | B1 B | C1 C
data S2 = A2 A | B 2

In this way the number of summands can be controlled without having to repackage the products that may occupy summands across multiple sums.