Skip to content

Instantly share code, notes, and snippets.

@xuyecan
Created December 29, 2018 08:33
Show Gist options
  • Save xuyecan/aea47b08ec1dbd1033da26883281d324 to your computer and use it in GitHub Desktop.
Save xuyecan/aea47b08ec1dbd1033da26883281d324 to your computer and use it in GitHub Desktop.
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