Hacker News new | ask | show | jobs
by mijoharas 2517 days ago
I remember the first time I tried to use them.

I just wanted to make some small functions for logging different types of things. I wanted to use parametric polymorphism to dispatch to different functions depending on the type of the thing I passed in. I think I ended up creating a few `log_type_foo` and `log_type_bar` functions rather than the single `log` function I wanted. It looked really ugly to my eye.

The thing I really wanted was parametric polymorphism. I seem to remember reading something where the go people think this is equivalent to generics.

EDIT: clarity

1 comments

Go supports parametric polymorphism by specifying arguments with an interface type.

  func DoWorkWith(foo Loggable) { ... }

  type Loggable interface {
    //for example
    LogTo(os.Writer)
  }