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 value at all (nil interface value). In the second case, it gets a static value of a concrete type, where the type is fixed at compile time. The programmer may choose any type which meets the constraint. The compiler may emit multiple versions of the same function, specialised to each type used, if it so chooses. On Wednesday, 15 December 2021 at 16:29:55 UTC bmhat...@gmail.com 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. > > On Wed, Dec 15, 2021 at 11:09 AM Jason Phillips <jasonrya...@gmail.com> > 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 >> >> On Wednesday, December 15, 2021 at 11:05:36 AM UTC-5 Jason Phillips wrote: >> >>> @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 types, terms of the form ~T, or >>> unions may only be used as type constraints, or as elements of other >>> interfaces used as constraints. They cannot be the types of values or >>> variables, or components of other, non-interface types. >>> >>> @Kurtis, that issue is about embedded fields (fields without explicit >>> field names) that use type parameters. >>> >>> [1] - https://tip.golang.org/doc/go1.18 >>> [2] - https://tip.golang.org/ref/spec#Interface_types >>> >>> On Wednesday, December 15, 2021 at 10:47:20 AM UTC-5 >>> kra...@skepticism.us wrote: >>> >>>> 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 <leonard....@gmail.com> >>>> 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 have the func `func Smallest[T constraints.Ordered](s >>>>> []T) T`. How do I write a table test for this func? Intuitively one >>>>> would try to store tests like this: >>>>> >>>>> tests := []struct { >>>>> Arr: []constraints.Ordered >>>>> Want: constraints.Ordered >>>>> }{...} >>>>> >>>>> But this is not permitted. Am I missing something why this behavior is >>>>> should be considered good? If a type constraint is nothing like an >>>>> interface... okay, but why call it interface then? >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "golang-nuts" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to golang-nuts...@googlegroups.com. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/golang-nuts/53df110e-8f34-490a-9b77-610dacffdbcfn%40googlegroups.com >>>>> >>>>> <https://groups.google.com/d/msgid/golang-nuts/53df110e-8f34-490a-9b77-610dacffdbcfn%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> >>>> >>>> -- >>>> Kurtis Rader >>>> Caretaker of the exceptional canines Junior and Hank >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/0ae9aed8-72d4-42a2-acf0-16d0bd6b08ecn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/0ae9aed8-72d4-42a2-acf0-16d0bd6b08ecn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e827b055-306d-4eee-b2e4-b27312bb36a8n%40googlegroups.com.