d.medina
07/15/2020, 4:54 PMd.medina
07/15/2020, 4:55 PMZach Klippenstein (he/him) [MOD]
07/15/2020, 5:01 PMwasyl
07/16/2020, 7:58 AMdarkmoon_uk
07/21/2020, 4:11 AMwasyl
07/21/2020, 6:11 AMclass ExternalLibraryClass, I would be able to make it implement my own interface AppInterface, and then pass instance of the class whenever interface is expected. This is a very powerful feature, and something that can’t be properly done without language supportdarkmoon_uk
07/21/2020, 12:27 PMUser) informally conforms to one of my own interfaces (Person), while formally it does not and cannot because it's a foreign type.
If I really need that conformance, architecturally, one common approach is a wrapper/proxy to add the interface conformance. But with this KEEP I could write a spec for the compiler to assert the behavioural conformance and treat User as a Person without wrapping?darkmoon_uk
07/21/2020, 12:27 PMwasyl
07/21/2020, 12:31 PMZach Klippenstein (he/him) [MOD]
07/21/2020, 4:28 PMZach Klippenstein (he/him) [MOD]
07/21/2020, 4:33 PMhashcode, and toString methods, even if they don't make sense for that type. In swift, these concepts are all represented by separate protocols, and types have to opt-in to them. This is much more typesafe than just calling hashcode on a third party type and hoping the library authors remembered to implement it. Another use case is Comparable. If you can, in your own code, make any type "implement" Comparable, you don't really need the concept of a Comparator. You could take any third-party library type and just provide an implementation of Comparable for it.