Created
December 29, 2018 08:33
-
-
Save xuyecan/aea47b08ec1dbd1033da26883281d324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Animal { | |
associatedtype H: Human | |
func action(by human: H) | |
} | |
protocol Human { | |
associatedtype A: Animal | |
} | |
class Man<T: Animal>: Human { | |
typealias A = T | |
var animal: A | |
init(animal: A) { | |
self.animal = animal | |
} | |
func foo() { | |
self.animal.action(by: self as! A.H) | |
} | |
} | |
class Cat: Animal { | |
typealias H = Man<Cat> | |
func action(by human: Man<Cat>) { | |
print("fuck") | |
} | |
} | |
Man<Cat>(animal: Cat()).foo() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment