shoenig/gopp-cs345 — Issue #5: Type Agnostic Structs/Functions
Author: shoenig
Created: 2011-10-19 03:15:56+00:00
State: open

This is the core of the project. Go should support a mechanism for type-agnostic data structures and functions. This could be through a template system like c++, a generics system like Java, or a macro system.

Generics are a third rate choice due to complexity and lack of "fit" with the rest of the language.

For starters what I want is a way to make something like this possible:

func min(a ?, b ?) ? {
if a < b {
return a
} else {
return b
}
}

Where the function is re-compiled for each type it gets used with. One obvious complication is that Go disallows overloading, so name obfuscation would become necessary. A nicety is that the Go compiler can then handle the type-checking for us. If it doesn't compile, then obviously the programmer tried to do something that doesn't make sense (like in the example, if a were a string and b were an int, there is no '<' operator between string and int).

Ultimately, I want type agnostic structs.
type Foo struct {
a ?
b ?
}
I need to think about this one.