Hacker News new | past | comments | ask | show | jobs | submit login

> Does anyone know the impetus for using [] in generics?

Yes: https://go.googlesource.com/proposal/+/refs/heads/master/des...




is it really the case that parsers can't tell the greater than sign in "a, b = w < x, y > (z)" without type information? or is it simply difficult to parse for some parsers?


It's a problem all languages with <..> need to solve one way or the other; see e.g. https://blog.dyvil.org/syntax/2016/04/19/angle-bracket-gener...

So for C# it's resolved "by examining the token after the closing >: If it is one of (, ), ], :, ;, ,, ., ?, == or !=, the expression is parsed as a generic method call."

I assume this works reasonably well; however, it's not hard to see how this might be a problem in some cases where the parser gets it wrong.


thanks for explaining :)


The doc says it's actually impossible, and I'm inclined to believe so. Rust has a similar problem in their case they adopted the "turbo fish" operator, where the generic function call would take the following form:

    let (a,b) = w::<x,y>(z);


Can you as a human? If you can't do it a parser can't do it either.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: