News for hackers. Stuff that matters.
Re:Sum Types in Go by TheDong on Friday December 26, 2014 @01:19AM (#8798240)
What do you mean? Isn't this a type alias: http://play.golang.org/p/J2gHol1Egd

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.

Re:Sum Types in Go by evmar on Friday December 26, 2014 @01:39AM (#8798278)
Grandparent is correct. You didn't make an alias, because it's not interchangable:

http://play.golang.org/p/fiz0NnduNF

(try running it)

Re:Sum Types in Go by Jayschwa on Friday December 26, 2014 @02:00PM (#8799776)
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_
Re:Sum Types in Go by jesstaa on Friday December 26, 2014 @02:24AM (#8798348)
It's not an alias, it's a new type. eg. http://play.golang.org/p/bXgryxNT0H
Re:Sum Types in Go by colin_mccabe on Friday December 26, 2014 @04:59AM (#8798566)
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.