Would square brackets allow replacing foo::<bar,baz> with foo[bar,baz]
so I realise there’s ambiguity…
in some contexts, foo[bar,baz] could be an array index or type-parameters on a function. (anything else?); but in either case, its a single node in the AST yielding a value
let x:foo[bar,baz] = ... // thats a type
x = foo[bar,baz]{......} // that must be a type, because its’ followed by {…struct initialiser…}
foo[bar,baz](a,b,c); // Thats ambiguous - could be variable[index expression] or function-name[types](arguments)
// however the overall shape of the AST is the same, unlike with <… > ambiguities
// once you’ve found the definition of ‘foo’ (a function? a variable?) could you figure out that it’s a function call, and swap the meaning of the node? in either case the foo[bar,baz] had to yield a callable.
Does that stretch the goal of simple parsing too far? I think rusts’ grammar for types is slightly different - but part of that is the angle brackets themselves; and if you want to pass computed values into type-parameters like C++ can, you’d want more of the regular grammar.
I guess there must be a reason why scala switched to something(index)
could expressions and types be given the same grammar, and then use other operators to give more meaning when taking types, e.g.
Vec.Option.int could be shorthand for Vec[Option[int]], and I gather some languages use a|b for anonymous variants (which sounds great to me)
(this would mean one namespace instead of separate namespaces for types/functions?)