For example: type Int int func (i Int) Add(j Int) Int { return i + j }
type Number<T Number<T>> interface { Add(j T) T } If we want Int satisfy the interface Number<Int>, we have to create two versions of function Int.Add, one for concrete type Int, one with generic type T And if we want to support: var i Int var v interface{} = i var n Number<Int> = v.(Number<Int>) We will have to create a stub for Int.Add in itable of Number, and dynamically adapt the parameter types at runtime. On Tuesday, June 21, 2016 at 12:24:12 AM UTC-7, andrew...@gmail.com wrote: > > >> While later I realized that we still need some parameter check in the > callee code to satisfy the interface matching (the generic version of each > function in my proposal). > > A am sorry but your judgements is not correct. > Here is a proofs: > 1. It is redundant to perform check of the correctness of the assignments > after when assignement already made. > > Eg. > > val i int > i = 0 > // It is redundant to perform check the correctness of the assignments of > `i` after when assignement of `i` already made. > > 2. Fucntion is a callable piece of code which CAN have initial variables > (function parameters) which SHOULD be assigned (via function arguments) > before function invocation. > > Of course, these parameters can be explicit and implicit. > Eg. receiver of the method is an implicit parameter but it still a > parameter (function variable which would be assigned before function > invocation implicitly by the compiler, or by the reflection construction). > > That is, this code is equilvalent. > > var i int > i = 0 > // other code, `i` already assigned > > func foo(i int) { > // other code, `i` already assigned > } > > > 3. Also you should to know that in a generic type system (type sytem with > the generic types) each type is potentialy a generic type. > Here is a proof. > > Each type in a generic type system looks like a function. > Type can have a [0..~] number of parameters which are declared by the type > declaration and whose parameters can be assigned by the type arguments. If > arguments omitted then parameters assigned to default values (types). > > > The same as the funtions. > > // Declare type with 2 parameters, K and V > type Type<K, V> {} > > // Declare type with 2 bounded parameters, K and V > type Type1<K string, V int> {} > > // Instantiate new type with a specified arguments (the same as the > function invocation) > // For simplicity we can imagine the following auto generated code > // if *__staticType1021 == nill { > // *__staticType1021 = __createGenericType(__getType(Type1), > __getType(string), __getType(bool)) > // That is, call to __createGenericType(*t RType, args... *RType) > // } > > // foo := __newobject(*__staticType1021) > > foo := Type1<string, bool>() > > Another story when we use generic type on the callee side. > > func (t *Type1) foo(key K) V { > // Here compiler always assume that the type of `t` is a generic type > `Type1` with a correctly assigned type arguments. > // Assigned arguments does not need to re-check > // ___type0 := __getTypeOf(t) > // Here is enough (since type are generic) rely only on that the each > type argument bound to the type parameter > ... > } > > > -- 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. For more options, visit https://groups.google.com/d/optout.