News for hackers. Stuff that matters.
Re:Golang generics proposal has been accepted by baby on Wednesday February 10, 2021 @03:32PM (#26094353)
Golang needed sum types (for options) and match statements (python got it after all...) way before it needed generics. CHANGE MY VIEW.
Re:Golang generics proposal has been accepted by zeugmasyllepsis on Wednesday February 10, 2021 @03:39PM (#26094430)
Sum and intersection types + pattern matching feels so natural in languages like F#, OCaml, Reason, and Elixir. I know they add a significant amount of complexity to the language, but the more I use them, the more I feel that the tradeoff lands in the goldilocks "just right" zone. I find myself missing them often.
Re:Golang generics proposal has been accepted by cies on Wednesday February 10, 2021 @03:46PM (#26094536)
> feels so natural

Yes. They are as important as records/structs a.k.a. product types.

> F#, OCaml, Reason, and Elixir

Haskell, Elm, PureScript, Kotlin, Idris, ...

> I know they add a significant amount of complexity to the language

Really? I dont think it can be so much more than generics :)

Elm has 'm and the whole language is 5k lines of code.

Re:Golang generics proposal has been accepted by sdfsfsf3kjdf on Wednesday February 10, 2021 @04:12PM (#26094877)
How exactly are you going to implement a type safe option type without generics? You either have to use interface{}, which is obviously not type safe, or write/generate an option type for every type contained within it. Sum types are a lot less useful if you don't have generics.
Re:Golang generics proposal has been accepted by alecbz on Wednesday February 10, 2021 @05:48PM (#26095871)
It could have been built in to the language. Tons of builtin features (slices, maps, channels) are already "generic".
Re:Golang generics proposal has been accepted by baby on Thursday February 11, 2021 @06:14PM (#26108806)
This
Re:Golang generics proposal has been accepted by cies on Wednesday February 10, 2021 @03:37PM (#26094408)
Yes. But null-safety is absolute on the top (as it is soooo hard, maybe even impossible, to add later).

Generics... Well, I just come from a Elm gig (knowing Haskell/C++/Java/Kotlin/Ruby) and I must say I was not too bothered with the lack of generics there.

Re:Golang generics proposal has been accepted by jasperry on Wednesday February 10, 2021 @03:47PM (#26094543)
Wait, doesn't Elm have parametric polymorphism like other ML-family languages? That's just as powerful as most languages' generics, and with a lot fewer brackets.
Re:Golang generics proposal has been accepted by sdfsfsf3kjdf on Wednesday February 10, 2021 @03:50PM (#26094579)
> Well, I just come from a Elm gig and I must say I was not too bothered with the lack of generics there.

Elm has generics.

Re:Golang generics proposal has been accepted by cies on Wednesday February 10, 2021 @03:55PM (#26094653)
Really? Why then there's List.map, Maybe.map, Array.map, and I have to select one of them? Is that not what generics would fix?
Re:Golang generics proposal has been accepted by sdfsfsf3kjdf on Wednesday February 10, 2021 @04:01PM (#26094744)
> Is that not what generics would fix?

No. That would be fixed by having something akin to typeclasses, traits or interfaces.

Elm's List, Maybe and Array are all defined using a generic type parameter.

Re:Golang generics proposal has been accepted by shakow on Wednesday February 10, 2021 @07:10PM (#26096591)
No, it fixes that you don't have to chose between ListOfInts, ListOfStrings and ListOfListOfArrayOfInt.

BTW, one doesn't have to chose between them in Go either, but only because there are under-the-hood generics for the native types, that are only accessible to the language designers.

Re:Golang generics proposal has been accepted by floxy on Wednesday February 10, 2021 @05:46PM (#26095861)
There is a terminology issue here, with "generic" being overloaded to mean different things. Parametric polymorphism is what Go is adding. You'd like to see something like ad hoc polymorphism in Elm, like type-classes in Haskell. But neither of those should be confused with the datatype generic programming.

https://en.wikipedia.org/wiki/Parametric_polymorphism

https://en.wikipedia.org/wiki/Ad_hoc_polymorphism

https://wiki.haskell.org/Generics

Re:Golang generics proposal has been accepted by eeperson on Wednesday February 10, 2021 @03:44PM (#26094512)
I think you want generics for many useful sum types (e.g. options) so you don't have to repeat your sum type definition everywhere it is used. Also, you can have options and matching without sum types (e.g. scala).
Re:Golang generics proposal has been accepted by merb on Wednesday February 10, 2021 @04:34PM (#26095136)
btw. scala 3 might change that. there is a language feature which can be turned on to have explicit nulls, which will be in the form of union/sum types: https://dotty.epfl.ch/docs/reference/other-new-features/expl...
Re:Golang generics proposal has been accepted by dragonwriter on Thursday February 11, 2021 @01:16PM (#26105106)
Python has all of those things, including generics, so whatever order they are needed in, “Python got it” doesn't argue for one over the others.