Re: [go-nuts] [generics] bring contracts back

2020-06-20 Thread Bebop Leaf
Personally I am happy with the current way of expressing constraints, i.e., interface-like + type lists, but I do think constraints and interfaces, are two different concepts, and forcing them into a same box does not mitigate the extra cognitive load needed to understand generics (which, as in

Re: [go-nuts] [generics] bring contracts back

2020-06-20 Thread Denis Cheremisov
Got one: https://rakyll.org/generics-proposal/ At the very bottom of the page, a person wrote a strange code func Do(type T io.Reader)(r T) { switch r.(type) { case io.ReadCloser: fmt.Println("ReadCloser") } } prog.go2:19:9: r (variable of type T) is not a

Re: [go-nuts] [generics] bring contracts back

2020-06-18 Thread Denis Cheremisov
> clear feedback on earlier versions of the design draft that contracts could be hard to understand. Yeah, sure. Now expect lots of materials throughout the web explaining "this part is for interface that is not supposed to be in a runtime but for compile time constraints". You understand better

Re: [go-nuts] [generics] bring contracts back

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 9:58 AM Denis Cheremisov wrote: > > IMO a groups of constraints are horrible with interfaces > > type CommonResponse(type E) interface { > GetError() E > } > > type CommonError interface { > GetCode() int32 > } > > func IsOK(type R CommonResponse(E), E CommonError)(

Re: [go-nuts] [generics] bring contracts back

2020-06-17 Thread Я
> if you find it more readable not only readable. I still can't get why they banned constraints on structs having some fields of certain type. With contracts they are easy to allow: contract NameField(T) { T Name string } and there's no hope with interfaces ср, 17 июн. 2020 г. в 21:37, Axel

Re: [go-nuts] [generics] bring contracts back

2020-06-17 Thread 'Axel Wagner' via golang-nuts
Ah sorry, I misunderstood. Please disregard :) On Wed, Jun 17, 2020, 20:36 Axel Wagner wrote: > You can always combine multiple interface constraints: > > type ConstraintA(type A) interface { > Foo() A > } > > type ConstraintB(type B) interface { > Bar() B > } > > type CombinedConstraint

Re: [go-nuts] [generics] bring contracts back

2020-06-17 Thread 'Axel Wagner' via golang-nuts
You can always combine multiple interface constraints: type ConstraintA(type A) interface { Foo() A } type ConstraintB(type B) interface { Bar() B } type CombinedConstraint(type A, B) interface { (ConstraintA(A)) (ConstraintB(B)) } func F(type A, B CombinedConstraint(A, B)) (...

[go-nuts] [generics] bring contracts back

2020-06-17 Thread Denis Cheremisov
IMO a groups of constraints are horrible with interfaces type CommonResponse(type E) interface { GetError() E } type CommonError interface { GetCode() int32 } func IsOK(type R CommonResponse(E), E CommonError)(r R) bool { switch r.GetError().GetCode() { case 0, 200, 201: