2 ms·
Five sets, but at any given place in the syntax, not all five are possible. (I would add function calls to the list—so, six.) In most languages, (grouping and
by klodolph 2y ago
Five sets, but at any given place in the syntax, not all five are possible. (I would add function calls to the list—so, six.)
In most languages, (grouping and compound statements) cannot syntactically appear in the same place as (indexing, records, type parameters, function calls). So we are immediately down to four.
Rust takes the approach that you use :: before type parameters, so they are easily distinguished from comparison operators at a syntactic level.
Go takes the approach that [] is just fine for type parameters—which seems pretty reasonable to me. In Go, there’s nothing that can be both indexed *and* take a type parameter.
- zarzavat 2y ago> In Go, there’s nothing that can be both indexed and take a type parameter. True, but TypeScript has a rule against type-dependent emit - it’s not allowed. Code must always do the same thing regardless of what the types are. And in any case JavaScript does allow indexing on functions, since functions are just objects.