Proposal: Interfaces for more generic code

This is a great idea, and I’d like this to happen.

The problem is that interfaces are typed, but in the rest of the language it’s not mandatory to type your methods.

So a user will create a type with def to_i without an explicit return type, and the compiler won’t consider that type.

For example BigDecimal has to_i without a return type. Same goes for BigFloat, Complex and maybe others.

The problem is that when you create an interface expecting to “capture” existing types with it, that might not happen because people might not put type annotations in methods. So you have to go tell them “hey, put type annotations there so they satifsy my interface”.

Instead, the current approach is to mark each of these types explicitly by including a module. It’s annoying, but it works. It also works like that in, for example, Haskell. There are no magical interfaces like in Go. Same goes for Rust, for Java, etc.

If we made all type annotations mandatory, then yes, sure. But without that “mandatory” aspect, I think interfaces can’t work.

This will also suffer the same problems we faced with abstract, like this one.

So I won’t create a POC for this, sorry :cry:

1 Like