Changeset 2410 for Papers/polymorphic-variants-2012
- Timestamp:
- Oct 19, 2012, 5:05:55 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Papers/polymorphic-variants-2012/polymorphic-variants.tex
r2409 r2410 65 65 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. 69 Constructors correspond to classes implementing this interface; pattern matching is emulated using the language's dynamic dispatch mechanism. 70 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. 71 74 72 75 [dpm: reword the above --- hard to phrase precisely ]
Note: See TracChangeset
for help on using the changeset viewer.