Re:More Good Programming Quotes (2016)
by Ace17 on Saturday July 22, 2017 @08:02AM
(#14826749)
polymorphism?
[ Parent
| on HN ]
I don't think that can be it. Polymorphism doesn't require existential types!
Closed polymorhpism can always be pattern-matched but it requires modifying all matchers. Open polymorphism is the default in OO interfaces: you can always implement a new type by adding code locally.
Since existential types can be monomorphised and compiled to binary code allowing type-safe plugins.
Yeah, I was referring to polymorphism as we have in OO, where old code can call new code.
I didn't even know "closed polymorphism" was a thing (is it equivalent to algebraic types?).
I'm not precise anymore with jargon concerning polymorphism (it's all the same to me), which I probably shouldn't do. I consider two factors: first closed/open (or finite/arbitrary) of 'remembering' an erased type, and second the sugar for nested 'remembering'. Almost all languages have both (open and closed) as either built-in, as a library or as a design pattern for that language. It boils down to either a tagged union or a function pointer. And both can be transformed to the other if needed.
Assembly, C have tagged unions & function pointers. Java has visitors, instanceOf, reflection. C++ has visitors, boost::variant, dynamic casts, mach7. Haskell has ADTs, pattern matching, existential quantification, Dynamic. Rust has pattern matching, traits, Any. Python, javascript, lua, lisp are dynamic, it's easy enough to create both.