3 ms·
Nope, I must say I have only used a small subset of languages from the FP-language-zoo, so my opinion on OCaml might be biased But as an example when writing T
by lairv 4y ago
Nope, I must say I have only used a small subset of languages from the FP-language-zoo, so my opinion on OCaml might be biased
But as an example when writing Typescript, I feel so frustrated of not having a clean way of doing pattern-matching
- pjmlp 4y agoYou will have to wait for JavaScript to add it first. The whole point of Typescript and why it is so successful, is because they only add type system on top of JavaScript. Pattern matching would introduce new language constructs beyond what is required for defining types.
- sn9 4y agoTypescript gets compiled to Javascript anyway. What's stopping any pattern matching construct from being compiled to vanilla JS? We already get stuff like type narrowing and generics.
- pjmlp 4y agoThe philosophy of not adding language constructs beyond what is required for the type system. Typescript code without type annotations should be JavaScript compatible, minus features still in flight for standardisation. There are other languages for that like ReasonML.
- zem 4y agoI think as long as they maintained it as a proper superset of javascript (i.e. all js code was valid ts code), adding a new language construct wouldn't hurt them much. see kotlin vs Java for a similar case
- pjmlp 4y agoExcept that isn't the design approach from TypeScript, all TS code without type annotations should be valid JS code. As for your Kotlin example, Dart's failure shown why it isn't a good approach. Kotlin also shows what happens when the underlying platform decides to go in another direction (value types, loom, default methods on interfaces), and the amount of boilerplate that needs to be generated to pretend to be like the host language. A language that only matters, thanks to the way Google is pushing it on Android to replace Java for anything besides system libraries.
- yawaramin 4y agoWhy wait? Just use ReScript. It's OCaml but adapted to fit natively in the JavaScript world.