class Animal {} class Cat: Animal {} struct Foo<Value> { var value: Value } extension Foo { func f() -> Animal { Animal() } } extension Foo where Value == Int { func f() -> Cat { Cat() } } print(Foo<Int>(value: 42).f())