What he's basically describing are GADTs ala Haskell and other enlightened languages. The GADTs are basically typesafe unions. Types that can be one of any types in a constrained set. The thing is that these types are just data. They don't have, and shouldn't have, any methods like an interface value might.
Go can achieve the same result as Haskell's GADTs albeit with more typing.
An example might be found in an interpreter for a Toy language. (apologies to
http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours)
There is a number of potential primitives in our language, an Atoms, Lists (of something), Numbers, Strings, and Boolean values. When the parser function runs, it will return whichever primitive it finds next. But how do represent what is a valid value to be returned by the parser? The answer is GADTs.
In Haskell:
data ToyVal = Atom String
| List [ToyVal]
| Number Integer
| String String
| Bool Bool
So we're saying that ToyVal can actually represent a String, a list of ToyVals, an Integer, or a Boolean.
So we can return a ToyVal from our parse function, then pattern match on it's type, and act accordingly.
Go can achieve similar results with more effort using:
type ToyVal interface {
toyvaldummy()
}
type Atom string;
type List []ToyVal;
type Number int;
type String string
type Bool bool
func (a *Atom) toyvaldummy() {};
func (a *List) toyvaldummy() {};
func (a *Number) toyvaldummy() {};
func (a *String) toyvaldummy() {};
func (a *Bool) toyvaldummy() {};This would allow you to specify that ToyVal can only be represented by these 5 types. This seems like a large amount of typing when compared to Haskell. In addition, we can do nothing to stop someone else from adding to that list. But, to me, it's a reasonable facsimile.
In either case, this allows us to call:
func handlePrimitive(text string)
{
val result ToyVal;
result = parseSomething(text);
switch t := result.(type) {
case Atom:
// do something with Atoms
case List:
// do something with lists
...
}
}