Changeset 2410


Ignore:
Timestamp:
Oct 19, 2012, 5:05:55 PM (7 years ago)
Author:
mulligan
Message:

Changes to Section 2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Papers/polymorphic-variants-2012/polymorphic-variants.tex

    r2409 r2410  
    6565We must introduce a new algebraic type with the additional constructor, lifting the old type---and any functions defined over it---into this type.
    6666
    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.
     67Moving 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.
     68In mainstream object-oriented languages such as Java algebraic data types correspond to interfaces, or some base object.
     69Constructors correspond to classes implementing this interface; pattern matching is emulated using the language's dynamic dispatch mechanism.
     70The interface specifies the permitted operations defined for the type.
     71In 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.
     72If the interface changes so must every class implementing it.
     73However, 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.
    7174
    7275[dpm: reword the above --- hard to phrase precisely ]
Note: See TracChangeset for help on using the changeset viewer.