3 ms·
Interestingly enough, OCaml has a great polymorphism story in its OO system. Because it is structurally typed with nearly automatic inference, you can in fact w
by int_19h 2y ago
Interestingly enough, OCaml has a great polymorphism story in its OO system. Because it is structurally typed with nearly automatic inference, you can in fact write completely generic code like `x#y(z)`, which magically "just works" for any x that has a method y that accepts z - all inferred and statically type-checked.
- yazzku 2y agoInteresting. Why doesn't the standard lib use that for the examples I listed?
- debugnik 2y agoBecause those types are not object types, so they don't have methods associated with them at all. This is unlike, say, CLR languages in which all types are object types. There's been research on modular implicits for OCaml to solve this more generally, but that's not landing upstream anytime soon.
- instig007 2y ago> Because it is structurally typed with nearly automatic inference, you can in fact write completely generic code like `x#y(z)`, which magically "just works" aka let's mix two jars of jam and shit via this funnel and see what happens.
- int_19h 2y agoOn the contrary, static and structural typing are a match made in heaven.