Skip to content

Instantly share code, notes, and snippets.

@alphazero
Last active August 31, 2017 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphazero/73e2de37802d4d8fe4572dc848aee53f to your computer and use it in GitHub Desktop.
Save alphazero/73e2de37802d4d8fe4572dc848aee53f to your computer and use it in GitHub Desktop.
half-baked idea sketch - module level genericity for Go
/* 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
import (
"p" //+build {K:string, V:[]byte}
)
func main() {
var x = p.X {"this-thing", []byte("it is generic"),}
var k string
var v []byte
k, v = x.Get()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment