4 ms·
Perhaps TypeScript is a very clean example of the duplication phenomenon you mention in that article, because unlike in most languages, static types are complet
by codeflo 4y ago
Perhaps TypeScript is a very clean example of the duplication phenomenon you mention in that article, because unlike in most languages, static types are completely erased during compilation. It’s literally a typecheck-time functional programming language bolted onto an existing dynamic runtime language. For some complex object manipulations, the cleanest thing to do is to write two independent recursive functions: a runtime one to compute the value, and a typelevel one to compute the resulting type.
- wtetzner 4y agoActually, I think types are erased in most typed languages, unless they support runtime reflection.
- codeflo 4y agoType erasure is a specific compilation technique, it means more than a lack of introspection capabilities. In most languages, a function taking a float and a function taking an int end up producing different compiler output (because they need to use different CPU registers). More to the point, this extends to generic/template functions with signatures like “void foo<T>(T arg)”, which then need to be monomorphized, that is, copied for each instantiation. Languages with type erasure simply drop the type argument instead of instantiating it.