When I say "type MyInt int" didn't I just type-alias int?
Edit: I'm aware that they're not able to be used interchangeably, but I think I've heard the term used in this context before. I think I'm actually incorrect here and have just heard people use an incorrect term and thought that was an actual go term for some malformed type alias.
When I say "type MyInt int" didn't I just type-alias int?
No, you created a new type.
cmccabe@keter:~/tmp> cat inta.go
package main
import "fmt"
type myfoo int
func printint(i int) {
fmt.Printf("i = %d\n", i)
}
func main() {
var foo myfoo
printint(foo)
}
cmccabe@keter:~/tmp> go build inta.go
# command-line-arguments
./inta.go:13: cannot use foo (type myfoo) as type int in argument to printint
You are probably thinking about "typedef" in C++, but go works differently in this case.
I would not consider your example to be one of a "type alias". Alias usually means that the names can be used interchangeably without a difference in behavior (i.e. casting). Go actually has some built-in aliases where this is the case. "byte" is an alias for "uint8". They can be used interchangeably. Here is an example of the distinction: http://play.golang.org/p/ukYCBqFeW_
When I say "type MyInt int" didn't I just type-alias int?
Edit: I'm aware that they're not able to be used interchangeably, but I think I've heard the term used in this context before. I think I'm actually incorrect here and have just heard people use an incorrect term and thought that was an actual go term for some malformed type alias.