Hacker News new | ask | show | jobs
by millstone 1911 days ago
"Safety" and "performance" are not always the most important considerations. For example, Apple uses OOP so that its frameworks can evolve without breaking client apps. NSDictionary is a dynamic object because it permits the implementation to be changed or replaced, and this comes at a cost of performance.
1 comments

Polymorphism isn't a trait unique to OOP; most, if not all, FP languages have that as well.
Right. But OOP makes it central, and builds around it, while FP de-emphasizes it in preference to ADTs.

Strings are a good illustration. Instead of an abstract polymorphic String type, Haskell provided a concrete String type as an ADT. This proved too inflexible, which is why we have Text, lazy Text, ShortText, etc. Compare to NSString which also has multiple representations but hides them behind a single polymorphic interface.

"OOP makes it central, and builds around it, while FP de-emphasizes it in preference to ADTs."

ADTs are not an intrinsic part of FP, as not all FP languages even have them.

I'd also question whether ubiquitous polymorphism is overall a good thing in a language, or whether it's misguided complexity. In most OOP languages, any public method can be polymorphic, but a polymorphic function is inherently less predictable than one dispatches off a single type.

This sounds like haskell’s backpack, which lets you swap implementations of a model interface at will. But maybe I’m misunderstanding what you meant.

Polymorphism is front an central to everything in Haskell, which is why your comment sound off to me.

Or you use -XOverloadedStrings and then you also have in Haskell multiple representations that follow a single polymorphic interface.
It does not. -XOverloadedStrings unlocks `fromString :: String -> a.` That is not a polymorphic string interface; it's just syntax sugar for making something else from a string literal.