4 ms·
All those features are present in other languages too, the premise that no other useful or mainstream languages don’t is false. For example Swift has all of tho
by julius_set 6y ago
All those features are present in other languages too, the premise that no other useful or mainstream languages don’t is false. For example Swift has all of those features.
- DaiPlusPlus 6y agoSwift doesn't have first-class intersection-types or discriminated-unions (it has a variation on Java's enum types, which are close, but not exactly the same, e.g. you can't use a custom type defined elsewhere as a discriminated-union type: you have to use an enum case as the containing type - this is not a huge problem, just an ergonomic frustration). Additionally, I don't believe Swift supports true structural typing (i.e. Duck-typing). If you have a method that accepts a protocol-implementing object, that object has to explicitly implement that protocol, it can't be inferred by the compiler. In a similar vein, C# also supports intersection type (but only intersection-of-interfaces in type-parameterized generic methods) or structural-typing (again, via generics with explicit implementation). Please correct me if I'm wrong, but to my knowledge Swift doesn't support call-site structural typing nor true intersection types (i.e. intersection of non-interface types).
- namelosw 6y agoSwift is missing a lot of features, and that's why you can see a lot of type operators and type-level programming in some TypeScript code. For example, there is no Higher-Kind type support in TypeScript, but with some primitives from TypeScript, it's not hard to hack it out yourself. I doubt it's viable in Swift. Among those mainstream languages, not many of them having such an advanced type system, with very few exceptions like Scala - even with GADT, dependent types ahead. It's light years ahead of its peers. But I believe there are still some abstractions can be expressed in TypeScript but not Scala because the gradually/dynamically typed languages start from the opposite side from the spectrum.