DEV Community

loading...

Discussion on: The Problem with Interfaces, and how Go Fixed it

Collapse
dfacastro profile image
Diogo Castro

Structural subtyping is a terrible approach. It means Go Interfaces can only abstract over a type's structure, but not its laws/semantics/algebra.

For example, not every type with a combine function is a monoid (combine must be associative). In Go, every type with combine is automatically a monoid.

Collapse
dean profile image
Dean Bassett Author

It only conforms to the interface if it has the correct parameters as well. The examples listed don’t include type information, which was my oversight when trying to make it simple.

Also, interfaces in Go describe what a structure does rather than what it is, and they should be used as such. So something with a combine method is usually a Combiner rather than something with a fancier name.

Collapse
dfacastro profile image
Diogo Castro

Also, interfaces in Go describe what a structure does rather than what it is, and they should be used as such.

Yes, that was precisely my point. They let you abstract over the signature of a function, but not over its laws. Therefore, Go's expressiveness is limited.