3 ms·
Pardon my ignorance, but can't this be more easily translated into terms of (modern) object oriented programming, where you avoid mutating state? Here, the "na
by vog 9y ago
Pardon my ignorance, but can't this be more easily translated into terms of (modern) object oriented programming, where you avoid mutating state?
Here, the "natural transformation" is a function that takes an input object which adheres to a specific interface (i.e. provides a set of specific methods), operates only on that input interface, and returns another object that conforms to the expected output interface.
Avoiding mutating state means that either those objects have no attributes, or that the state can only be set on construction. (In FP speak, this corresponds currying of common parameters. Or to an internal abstract type, if the constructor is private and you can only create it via a specific set of static methods).
Is this modern style of OOP equivalent to "Functor-Oriented Programming", or am I missing something?
- deleted 9y ago[deleted]
- kraghen 9y agoOne important aspect of programming with functors is the ability to quantify over them, i.e. higher-kinded types. This is crucial for building reusable components on the functor-level of abstraction. In modern OOP this would amount to quantifying over interfaces which is typically not even possible in those languages.
- lmm 9y ago> Avoiding mutating state means that either those objects have no attributes, or that the state can only be set on construction. (In FP speak, this corresponds currying of common parameters. Or to an internal abstract type, if the constructor is private and you can only create it via a specific set of static methods). I don't think the style you're talking about is something that most people would call "object oriented programming" ("modern" or otherwise). Indeed the usual name for the programming style in which you avoid mutating state is "functional programming".
- vog 9y agoMaybe, but the terms "class", "method" and "interface" are more commonly understood than "functor" or "natural transformation". So for better understanding by the general public it may make sense to offer an explaination in terms of OOP, even if what is described is more FP style than OO style.
- lmm 9y agoFunctors are functors, natural transformations are natural transformations; neither has much in common with classes, methods or interfaces. Functors are being used to achieve composition here, but the use of functors is an essential part of the pattern; talking about "composition-oriented programming" would be vague to the point of meaninglessness (every programmer believes they're being compositional), and there simply isn't an OO equivalent of open recursive types as far as I know.