Last active
August 31, 2017 12:15
-
-
Save alphazero/73e2de37802d4d8fe4572dc848aee53f to your computer and use it in GitHub Desktop.
half-baked idea sketch - module level genericity for Go
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 | |
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