Sums and Types in Programming Languages
It turns out that some of those equations also hold for the type systems of many programming languages.
Zero, or the empty set, corresponds to an empty type.
Plus, or union, corresponds to a type constructor that allows values of several different types to belong to the sum type.
Times, or product, corresponds to a type constructor that allows values of several different types to be combined into a single value of the product type.
Consider the C programming language.
In C, what corresponds to 0?
Thevoid
type.In C, what corresponds to +?
Theunion
type constructor.In C, what corresponds to ×?
Thestruct
type constructor.
Now consider Java.
What corresponds to 0?
TheVoid
pseudo-type.What corresponds to +?
Abstract classes and interfaces.What corresponds to ×?
Concrete subclasses and classes that implement interfaces.