On Tue, Feb 6, 2024 at 6:43 AM Victor Manuel “Vitu” Giordano
<
vituc...@gmail.com> wrote:
>
> I'm wondering why the language allow me to write something like this:
>
> type IncFunc func(a int) int
>
> type Incrementor interface {
> IncFunc // <-- THIS is allowed
> IncQuantity() int
> }
>
> (RTR example here)
>
> I don't get how I can make leverage of that.. or if has any sense at all 🥴😵💫
> As I recall an interface is a set of methods, and a method do have a name... the thing here is that the name if the name of the type not the function's name.
An interface type like that can be used as a constraint for a type
parameter. It can't be used as the type of a variable. As a type
parameter constraint it means that the type argument must be IncFunc.
It's fairly useless, but follows from the other rules about type
parameter constraints.
Ian