On Wed, 19 Sep 2018 09:32:39 -0500
Robert Engels <reng...@ix.netcom.com> wrote:

> This is not what I am referring to. I am stating that with N generics types
> in a method the developer needs to write NxN case methods. Not feasible. 

Wrong. On two axis.

1. As stated in proposal, CGG has no "generic type" (generic data).

CGG stays entirely within comfort zone of the current Go type system.
No new things. CGG allows for readable generic **code** only.

Within CGG proposal you can **not** describe generic data using 
blocks of more grained generic data; i.e. in c++/java's matrioshka style.
By design. 

2. CGG generic code will operate "on types or part thereof".

Example Sum, in its most compact version

func (x type []K) Sum() (r type K) {
  for type K range int64(), uint64(), float64(), complex128()
  for _, v := range x {
    r += v
  }
  return
}

operates on any member of **infinite** set of concrete types
that has base type of either: int8, int16, int32, int64, uint8,
uint16, uint32, uint64, float32, float64, complex64 or complex128.

The developer implementing generic solution needs to write 
`for _, v := range x {;r+=v;};return;};` source. 

Above source makes to object code that will run alike for
`type my1 int8` and `type my2 int64`. Possible that it will be
a single variant for "all signed integers".

( From the contract one can infer, that Sum as stated may have up to 4,
and **at most** 12 emitted variants. None of which written directly
by the developer. )

In the second version, one that is meant to act also on some outstanding
type, the specialization is the devoloper's to decide. She decided to make
it for something like big.Int /T = big.Int/? Hmm.. I only need Add, so make
it more generic. `(*K) Add(K, K)` constraint allows for an x being a member
of infinite set of concrete types that "have method Add" of given signature.
Big.Int just happens to be member of that set.

func (x type []K) Sum() (r type K) {
 for type switch {
 case K range int64(), uint64(), float64(), complex128():
      for _, v := range x {
         r += v
      }
 case K (*K) Add(K, K): 
      for _, v := range x {
         r.Add(r,v)
      }
 break
 }
 return
}

CGG allows for specialized generic code. With "all types something that
allowed types have in common" occupying a single case.

Within other generic package, eg. webcommerce one, developer is free
to define and use other Sum - domain specific. Eg one that sums all
posible types of virtual "items" kind:

package "webo"

func (x type []K) Sum() (r int) {
 for type K.Value = int()
 for _, v := range x {
    r += v.Value
 }
 return
}

this Sum will take as x any struct with Value field that happens
to be int based. So Ticket (s) of below can be webo.Summed too.

type Reward int8
type Ticket struct { 
    n string 
    Value Reward
}


-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

-- 
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.

Reply via email to