Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-20 Thread Ian Lance Taylor
On Mon, Dec 20, 2021 at 4:04 AM Leonard Mittmann wrote: >> >> As to _why_ this is the case, the generics proposal has a section about that: >> https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#permitting-constraints-as-ordinary-interface-types > > @Jason

Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-20 Thread Leonard Mittmann
> > As to _why_ this is the case, the generics proposal has a section about > that: > > https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#permitting-constraints-as-ordinary-interface-types @Jason Phillips Thanks for pointing me here. @Ian Lance Taylor I

Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-15 Thread Ian Lance Taylor
On Wed, Dec 15, 2021 at 3:24 AM Leonard Mittmann wrote: > > I just learned that type constraints, which are defined as interfaces are > actually not usable in all the places "normal" interfaces can be used in. > E.g., why can a constraint interface not be uses as a struct type? > > Let's say I

Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-15 Thread Ian Lance Taylor
On Wed, Dec 15, 2021 at 8:29 AM Brian Hatfield wrote: > > I read that and I genuinely do not understand why interfaces now mean two > distinct incompatible things. I think this is going to confuse a lot of > people. This is perhaps pedantic, but the two meanings are not incompatible. The set

Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-15 Thread Brian Candler
A function which takes a value of an interface type, and a function which takes a value of a constrained generic type, are certainly two different things. In the first case, it gets a dynamic boxed value which at runtime may contain a value of any type that implements that interface - or no

Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-15 Thread Brian Hatfield
I read that and I genuinely do not understand why interfaces now mean two distinct incompatible things. I think this is going to confuse a lot of people. On Wed, Dec 15, 2021 at 11:09 AM Jason Phillips wrote: > As to _why_ this is the case, the generics proposal has a section about > that: > >

Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-15 Thread Jason Phillips
As to _why_ this is the case, the generics proposal has a section about that: https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#permitting-constraints-as-ordinary-interface-types On Wednesday, December 15, 2021 at 11:05:36 AM UTC-5 Jason Phillips wrote: >

Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-15 Thread Jason Phillips
@Leonard, type constraints can only be used as type parameters, using them as normal interfaces is currently not allowed. See the notes in the draft release notes[1] or the draft 1.18 spec[2]. > Such interfaces may only be used as type constraints. > Interfaces that contain non-interface

Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-15 Thread Kurtis Rader
This was asked 15 hours ago in the thread with the subject line "Go 1.18 beta1: Embedding Type Parameter in struct definition is an error". :-) See https://golang.org/issue/49030. On Wed, Dec 15, 2021 at 3:24 AM Leonard Mittmann wrote: > I just learned that type constraints, which are defined

[go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-15 Thread Leonard Mittmann
I just learned that type constraints, which are defined as interfaces are actually not usable in all the places "normal" interfaces can be used in. E.g., why can a constraint interface not be uses as a struct type? Let's say I have the func `func Smallest[T constraints.Ordered](s []T) T`. How