1 comment

[ 0.25 ms ] story [ 10.9 ms ] thread
>Anywhere that accepts an Operation Enum type will just as happily accept an int.

This isn't quite true. Operation is a different type to int, and a function that expects an int can't be passed an Operation or vice versa. However, Go numeric literals are untyped and Go can interpret an integer literal as a value of type Operation where appropriate. This can give the false impression that int and operation are interchangeable as far as the type system is concerned. Here's an illustrative example:

    package main    

    type Foo int    

    const (
      FooA Foo = iota
      FooB
    )    

    func main() {
      var i int = 1
      var f Foo = 1       // this is ok (literal 1 can represent value of type Foo)
      f = i               // not ok
      i = f               // not ok
      (func(f Foo) {})(i) // not ok
      i = FooA            // not ok (because FooA is a typed constant)
    }