3 ms·
OCaml-style structural typing cannot handle deciding at runtime what fields an object has. Arguably it's best to know this statically, but dynamic language user
by catnaroek 10y ago
OCaml-style structural typing cannot handle deciding at runtime what fields an object has. Arguably it's best to know this statically, but dynamic language users make extensive use of the ability to dynamically add fields to an object.
- nine_k 10y ago...which, of course, make it easier to assume the presence of a particular field and crash. Using an explicit map for dynamic attributes at least makes you aware what is guaranteed and what is optional. This removes much of the neat magic that such a dynamic approach affords to languages like Ruby, JavaScript, and, to a lesser extent, Python.
- jon_smark 10y agoIn the case of OCaml, the structural subtyping of object fields can never cause a crash, because it is verified at compile-time.