Re:Go generics draft design: building a hashtable
by ccktlmazeltov on Wednesday June 17, 2020 @07:16PM
(#23557986)
I really wish Go would pursue sum types instead of generics
[ Parent
| on HN ]
Re:Go generics draft design: building a hashtable
by qtplatypus on Wednesday June 17, 2020 @08:19PM
(#23558413)
Sum types and Generics solve different but related problems. So they are not really comparable. I would like to see both get implemented.
Re:Go generics draft design: building a hashtable
by ccktlmazeltov on Wednesday June 17, 2020 @09:58PM
(#23558999)
I'd say it's really hard to abuse sum types, I wouldn't say the same of generics.
Re:Go generics draft design: building a hashtable
by qtplatypus on Friday June 19, 2020 @12:21AM
(#23570943)
That is true. However sum types don't allow us to abstract over common code. For example a sum type wouldn't allow us to create a type safe channel "fan in" function that works for all channel types.
Re:Go generics draft design: building a hashtable
by mrath on Wednesday June 17, 2020 @07:30PM
(#23558087)
Sum types without generics will still be good enough? I think for things like Option/Result we need both sum types and generics.
Re:Go generics draft design: building a hashtable
by ccktlmazeltov on Wednesday June 17, 2020 @09:58PM
(#23558998)
I don't think you would need user generics for this to work.
Re:Go generics draft design: building a hashtable
by OceanSpray on Wednesday June 17, 2020 @11:21PM
(#23559490)
Without generics, sum types would have to be a built-in like maps and arrays.
With generics, discriminated unions can take on all sorts of user-defined shapes.
Re:Go generics draft design: building a hashtable
by kccqzy on Thursday June 18, 2020 @03:13AM
(#23560571)
Without generics, structs can take on all sorts of user-defined shapes. It's just that the types of its fields are fixed at declaration.
Without generics but with sum types, the sum types can still take on all sorts of user-defined shapes. It's just that the types of its various alternatives are fixed at declaration.
Re:Go generics draft design: building a hashtable
by masklinn on Thursday June 18, 2020 @01:28AM
(#23560050)
Non-generic sum types are useful but you can’t build an option or result type out of them, so the usefulness is somewhat hampered.
Re:Go generics draft design: building a hashtable
by ccktlmazeltov on Thursday June 18, 2020 @03:50PM
(#23567125)
But you don't need to, generic Option and Result types could be built as part of the standard library.
Re:Go generics draft design: building a hashtable
by masklinn on Saturday June 20, 2020 @09:44AM
(#23583900)
Yes but then you need neither sum types nor user-defined generics, you can just build-in whatever sugar is useful or necessary (possibly repurposing existing sugar e.g. the `select` statement).
Re:Go generics draft design: building a hashtable
by ccktlmazeltov on Sunday June 21, 2020 @03:15PM
(#23594548)
sum types are still super useful imo without generics.
Re:Go generics draft design: building a hashtable
by shp0ngle on Thursday June 18, 2020 @03:56AM
(#23560822)
Aren't the new interfaces from the draft, where you can list bunch of possible types, sum types?
edit: oh. no.
https://go.googlesource.com/proposal/+/refs/heads/master/des...