3 ms·
Maybe already fixed, but here are a couple things I noticed: Go methods have to be defined in the same package as their receiver's type. As a result, you can o
by skybrian 10y ago
Maybe already fixed, but here are a couple things I noticed:
Go methods have to be defined in the same package as their receiver's type. As a result, you can only add methods to your own types, not someone else's.
Also, the article claims that Go interfaces are similar to Elixir's pattern matching but I don't see a resemblance. Perhaps clarify that?
- brightball 10y agoBut you can define an interface that matches someone else's types and then attach the method to it. The main similarity I was going for was the way that an interface fits anything that matches it, rather than being directly implemented by the type. A method could be attached to an interface that matches a struct with two specific variables while Elixir could define a pattern on a function that worked for any struct that contained those two variables. They are both doing a similar thing a different way.
- riwsky 10y agoThe confusion with GP might be that you can't, in fact, define an interface and attach methods to it. More info @ https://golang.org/ref/spec#Method_declarations https://golang.org/ref/spec#Method_declarations