Last active
August 29, 2015 14:23
-
-
Save kongtomorrow/77c53e32ecf50b94f3c1 to your computer and use it in GitHub Desktop.
associated types for Brent
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 Value : Equatable { | |
} | |
protocol Smashable { | |
typealias TargetValue : Value | |
func valueBySmashingOtherValue<SomeOtherValue : Value>(value: SomeOtherValue) -> TargetValue | |
} | |
struct Bar : Value { | |
} | |
func ==(lhs:Bar, rhs:Bar) -> Bool { | |
return false | |
} | |
struct Foo : Value, Smashable { | |
func valueBySmashingOtherValue<SomeOtherValue : Value>(value: SomeOtherValue) -> Bar { | |
return Bar() | |
} | |
} | |
func ==(lhs:Foo, rhs:Foo) -> Bool { | |
return false | |
} | |
// or actually, is Smashable supposed to extend Value and always smash other stuff to its own type? If so, maybe this, | |
protocol Value : Equatable { | |
} | |
protocol Smashable { | |
func valueBySmashingOtherValue<SomeOtherValue : Value>(val: SomeOtherValue) -> Self | |
} | |
struct Bar : Value { | |
} | |
func ==(lhs:Bar, rhs:Bar) -> Bool { | |
return false | |
} | |
struct Foo : Value, Smashable { | |
func valueBySmashingOtherValue<SomeOtherValue : Value>(val: SomeOtherValue) -> Foo { | |
return Foo() | |
} | |
} | |
func ==(lhs:Foo, rhs:Foo) -> Bool { | |
return false | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment