4 ms·
Their union type syntax looks like Ceylon's. I rather like it. Union types with pattern matching would be the logical step, would it not? I wish for something
by lobster_johnson 12y ago
Their union type syntax looks like Ceylon's. I rather like it.
Union types with pattern matching would be the logical step, would it not? I wish for something like:
match getResults() {
case e: Error: ...
case r: Results: ...
}
- aikah 12y agoHere is the issue,at the end of the day,Typescript is just javascript with compile time type checking.Pattern matching would mean introducing "new" semantics which would make the compiled code much less readable than it is today. Tomorrow if I want to drop Typescript,I can,because it still outputs readable javascript.Introduce something like pattern matching and it will not be an option anymore.
- Horusiath 12y agoI actually like cleanliness of Javascript generated from Typescript code. However I don't think that pattern matching would be more intrusive than, for example, module or class generation. Basically example from above could be compiled down to something like: var x = getResults(); if(x instanceof Error) { ... } else if(x instanceof Results) { ... }
- lobster_johnson 12y agoAll the TypeScript examples use "instanceof". That's what a pattern matching block like this would compile down to, surely. And pattern matching on literals (eg., [x|xs]) would also translate to perfectly adequate JavaScript.
- codygman 12y agoHave you checked out purescript[0]? 0: http://www.purescript.org/ http://www.purescript.org/
- lobster_johnson 12y agoYes, it looks quite nice. I might experiment with it for a personal project at some point. Is it easy to use NPM modules without any extra glue?
- codygman 12y agoI believe they can be very easily used if they are CommonJS modules? I'm not sure, but I'm almost positive the amazing Purescript Book[0] has an answer for you. 0: https://leanpub.com/purescript/read https://leanpub.com/purescript/read