On Wed, Dec 15, 2021 at 3:24 AM Leonard Mittmann
<leonard.mittm...@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?

Aside from the rest of the conversation, note that your suggestion is
never going to work, because you aren't going to be able to write the
next steps in which you try to instantiate a function with an element
of a slice.  You can only instantiate functions with types known at
compile time, not with types known at run time.

Ian

-- 
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/CAOyqgcUyeZq9HBw6DyEZ7dL2U6mv6YQPFM%3DaKR-zZOnk6L6W4w%40mail.gmail.com.

Reply via email to