Legend:

We must introduce a new algebraic type with the additional constructor, lifting the old type---and any functions defined over it---into this type.

66

66

67

Moving sideways, we can compare and contrast functional programming languages' use of algebraic data paired with pattern matching with the approach taken by object-oriented languages.

68

In mainstream object-oriented languages such as Java algebraic data types correspond to class hierarchies, each constructor corresponding to a subclass in this hierarchy.

69

Pattern matching is emulated using a dynamic dispatch mechanism.

70

Using the object-oriented approach it is easy to add a new `case' to a given hierarchy: just introduce a new subclass.

67

Moving sideways, we can compare and contrast functional programming languages' use of algebraic data paired with pattern matching with the approach taken by object-oriented languages, or extending the root object.

68

In mainstream object-oriented languages such as Java algebraic data types correspond to interfaces, or some base object.

The interface specifies the permitted operations defined for the type.

71

In contrast to the functional approach, it is hard to enlarge the set of operations defined over a given type without altering the entire class hierarchy.

72

If the interface changes so must every class implementing it.

73

However, note it is easy to extend the hierarchy to new cases, corresponding to the introduction of a new constructor in the functional world, by merely adding another class corresponding to that constructor implementing the interface.