let sum (x:'T) (y:'T) = x + y
I have no idea why you even have to specify that a method is generic shouldn't it be generic by inference?I'm guessing that it uses a context sensitive grammar that doesn't allow you to use string literals for variable names.
public class Foo<T> { ...
a method like:
public void EatAFoo<T>(...
and usage like:
var f = new Foo<int>();
someObj.EatAFoo<int>(...
I don't see how any of these cases could be confused with a greater than or less than operator. Could you expand on where the problem comes in?
See the C# specification section 9.2.3 (grammar ambiguities) for more details: http://www.ecma-international.org/publications/files/ECMA-ST...
myclass<3>4>
can only be a syntax error because you can't have a value in there, inly a type nameOn the other hand, [] is used for arrays in java so it _would_ conflict with something
It is a semantic error, not a syntax error (in the sense that an annotated grammar CANNOT, without semantic analysis, find that this is an error).
The example given in this comment, F(G<A,B>(7)) is syntactically ambiguous and can only be resolved to either F( (G<A) , (B>(7) ) - a two argument function call, or F( (G<A,B>(7)) ) - a one argument function call - when the types of F, G, A and B are known.
Also, things like F<G<A>> (which are perfectly legal) make lexing very hard - you can't assume '>>' is the shift right token without syntactic (and semantic) analysis. Or, you can decide like early C++ that you must write it F<G<A> > which is confusing.
AFAIK the syntax for passing type arguments to a generic method in the latter would be
obj.<A,B>G(7)
so F(G<A,B>(7))
is once again unambiguous, at a syntactic level.It would seem the java designers thought of the issue :)
Although C# and Java do not suffer from the craziness that is C++, by virtue of requiring a class name, e.g.
is unique to C++ - but still, all lexing/parsing/syntax highlighting/analysis of the language is much harder because of this horrible choice.For heaven's sake, please use {} or [] or some other character which does not also function as an infix operator.
(Even APL and K, which overload every character in fifty different ways, don't mix grouping with infix operators)