News for hackers. Stuff that matters.
Re:A concise guide to the latest Go generics draft design by irq-1 on Thursday June 18, 2020 @02:50PM (#23566300)
With a 'generic' interface declaration we could remove the (type T) annotations. The compiler would still know what type parameters are needed (because they are used in the function prototype.)

    // generic works like an interface
    type T generic {
        comparable  // generic allows additional constraints
    }
    
    // we know the type parameters by the use of T
    // (because T is generic type)
    func Same(a, b T) T { ... }
    
    // calls may still need to include the type parameters,
    // but type inference will generally make them unnecessary
    s := Same(type string)("hi","howdy")
    s := Same("hi","howdy")

There are no comments on this comment yet.