Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Unfortunately [T] is also ambiguous with the current Go syntax. The parser can't distinguish an array declaration from a generic type.


How about the following:

  contract Addable(t T) {
  	t + t
  }

  func Sum.<T Addable>(x []T) T {
	var total T
	for _, v := range x {
		total += v
	}
	return total
  }
It has the nice property that it's somewhat analogous to type conversions, the grammar should be unambiguous, and it's much less visually confusing than re-using parentheses IMO.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: