Last active
August 31, 2017 12:24
-
-
Save alphazero/4e31aa4cce94fbb8b60c7372b21a6684 to your computer and use it in GitHub Desktop.
A refinement of the half-baked idea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* define generic package */ | |
// file p.go | |
package p | |
typevar K generic.ComparableType // poor man catagory | |
typevar V generic.AnyType // ^^ | |
import (...) | |
type X struct { | |
k K | |
v V | |
} | |
func (p *X) Get() (K, V) { return p.k, p.v } | |
// ----------- | |
/* use generic package - module type directive decl. can be done various way */ | |
package main | |
/* possible way for having n distinct type flavors of a given gen package in same source */ | |
import ( | |
psb "p" //+build {K:string, V:[]byte} | |
pss "p" //+build {K:string, V:string} | |
) | |
func main() { | |
var x = psb.X {"this-thing", []byte("it is generic"),} | |
var k string | |
var v []byte | |
k, v = x.Get() | |
var x1 = pss.X {"this-thing", "it is generic",} | |
var k1, v1 string | |
k1, v1 = x1.Get() | |
} /* the Q is how far does this get us .. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sans the hypothetical
generics
package (magic package alabuiltin
), this is mostly the build tool chain, so yes, code generation.