Hacker News new | ask | show | jobs
by nepeckman 1947 days ago
Comparable to TypeScript, but a little weaker in the advanced features. Nim object types and tuple types are similar to TypeScript interface definitions and just as light weight. The type inference is pretty similar, but Nim's is a little weaker. Nim also has object variants, which can achieve most of what I want out of union types. TypeScript has a pretty long list of advanced typing features, like key types, mapped types, and conditional types, which Nim cannot express. But the Nim macro system can work here in taking code and modifying it before the type system runs.
1 comments

Sorry, not just a little weaker. A _lot_ weaker. It lacks union and intersection types, and to my mind this is kind of inexcusable in a modern language. I'm not even talking about pattern matching, union types are simply necessary in an expression oriented language. It's that simple. Then, intersection types are the dual of union types.

(By the way, Rust lacks union types too, and it makes the language absolutely insufferable. Simply adding, say, a print statement as the last expression in one branch of an if statement changes that branches type, producing an error due to A/B type mismatches There is often no valid reason, e.g. in the case your branch isn't assigned to an expression. Even if it were, the type of that expression should be a union type: problem solved. It's so basic and so obvious, that Algol 68 got it right back in the 60s. Why on earth would you add discriminated unions but _not_ unions? It makes no sense.)

(I'm going to go off on a second tangent now: can we please just dust off the cool ideas in that language, like references represented in the type system, rather than replicating C++'s god-awful value categories and even _more_ reference squiggles? Consider how C++'s awfully complex [] move semantics could be expressed in that language!]).

[] https://www.reddit.com/r/cpp/comments/ll2azr/move_simply_sut...