(I suspect this is just another "generics" proposal masquerading as something else - but I could find a discussion of this using search)
I was wondering about the possibility of passing concrete types to functions as parameters - the onyl requirement being that the concrete type satisfies the interface And to minimize pain I only insist on using new, make, (and any interface methods) eg package main import ( "fmt" ) type ( I interface { ToString() string } B byte F float32 ) func (b B) ToString() string { return fmt.Sprint(b) } func (f F) ToString() string { return fmt.Sprint(f) } func makeStringy(x %I) I { //lets use % here to indicate x "is type" not "of type" xarr = make([]x, 10) //nonsense example of using make return x[3] } func main() { var ( b1 B = 1 f1 F = 1.0 ) fmt.Println(b1.ToString(), f1.ToString()) b2 := makeStringy(B) f2 := makeString(I) fmt.Println(b2.ToString(), f2.ToString()) } So my question is not really "is this a good idea" (I think its ok) - but "how easy would this be to do? (and if implemented would it contain extra run time overhead compared to that already used when implementing interfaces ? The key part of the example is f the function "makeStringy" - all is required here is that x is a Type that satisifies the interface I As I understand it data passed as an interface already contains a back reference to the underlying type (or the other way round) .. so here when I pass a type to the function (as an interface implementing variable) I need a back reference to the type .. and the only way I can use the variable is make and new - so the additional implementation details are minimal. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c26c857e-17b4-4275-b981-2102229d5479%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.