You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was discussing what I learned with a friend of mine, which pointed out that what is done in the chapter, implementing an interface that doesn't care about specifics of the implementation, but expecting a specific set of inputs and outputs, alongside their types, is actually ad-hoc polymorphism.
I read the introduction of the wikipedia article (I have to admit I wasn't too familiarized with the concept) and indeed, since we have different function definitions for each of the types (Rectangle, Circle and Triangle), it seems like it is ad-hoc. On the other hand, the interface itself doesn't really care about the implementation, and behaves the same, regardless of the type (Rectangle, Circle and Triangle).
What is it then? Did we really implement parametric polymorphism or ad-hoc polymorphism in the chapter? Is the type indifference at the interface level or the implementation level? If it is really ad-hoc, what would constitute parametric polymorphism in Go (and vice-versa)? Also, what do generics add to this discussion?
The text was updated successfully, but these errors were encountered:
Indeed, what’s done in the referenced chapter is a form of function overloading, which is an application of ad-hoc polymorphism. Go does also support generics, which are an application of parametric polymorphism.
I just got through Structs, methods and interfaces and at the end of the chapter, wrapping up the concepts, it is stated that
Declaring interfaces so you can define functions that can be used by different types (parametric polymorphism)
linking to https://en.wikipedia.org/wiki/Parametric_polymorphism.I was discussing what I learned with a friend of mine, which pointed out that what is done in the chapter, implementing an interface that doesn't care about specifics of the implementation, but expecting a specific set of inputs and outputs, alongside their types, is actually ad-hoc polymorphism.
I read the introduction of the wikipedia article (I have to admit I wasn't too familiarized with the concept) and indeed, since we have different function definitions for each of the types (Rectangle, Circle and Triangle), it seems like it is ad-hoc. On the other hand, the interface itself doesn't really care about the implementation, and behaves the same, regardless of the type (Rectangle, Circle and Triangle).
What is it then? Did we really implement parametric polymorphism or ad-hoc polymorphism in the chapter? Is the type indifference at the interface level or the implementation level? If it is really ad-hoc, what would constitute parametric polymorphism in Go (and vice-versa)? Also, what do generics add to this discussion?
The text was updated successfully, but these errors were encountered: