Hacker News new | ask | show | jobs
by sukunrt 2851 days ago
A question on generics from the docs

if the declaration is

func Keys(type K, V)(m map[K]V) []K

why do we need to call it like

keys := Keys(int, string)(map[int]string{1:"one", 2: "two"})

can't the types int and string be inferred from

Keys(map[int]string{1:"one", 2:"two"})

1 comments

They are. Further in the draft there is an example:

  var x []int
  total := Sum(x) // shorthand for Sum(int)(x)
ah crap. how did I miss that! Thanks!