Skip to content

Instantly share code, notes, and snippets.

@kongtomorrow
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kongtomorrow/77c53e32ecf50b94f3c1 to your computer and use it in GitHub Desktop.
Save kongtomorrow/77c53e32ecf50b94f3c1 to your computer and use it in GitHub Desktop.
associated types for Brent
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