Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've never worked in a language that allows you to declare some type you don't control adheres to an interface. Just out of curiosity and in case anyone else reading has the same question, can you list some? Coming from Java and C++, this is part of the value I see in Go's implicit interfaces.


Rust is the language I'm thinking of right now. If you declare a trait (what Rust calls interfaces), you can also implement that trait on any type.

The basic rule is you can implement a trait on a type if you declared either the trait or the type yourself. You just can't implement someone else's trait on someone else's type.

But Obj-C also allows for the same thing. You can declare @protocol (interface) conformance in a class category, and you can declare your own category on someone else's type.


Scala and Rust. Haskell, if you consider typeclasses interfaces.


Thanks! One of these day I would like to do some side projects in each of these.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: