Skip to content

Instantly share code, notes, and snippets.

@kongtomorrow
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save kongtomorrow/77c53e32ecf50b94f3c1 to your computer and use it in GitHub Desktop.

Select an option

Save kongtomorrow/77c53e32ecf50b94f3c1 to your computer and use it in GitHub Desktop.

Revisions

  1. kongtomorrow revised this gist Jun 21, 2015. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -23,19 +23,25 @@ func ==(lhs:Foo, rhs:Foo) -> Bool {

    // or actually, is Smashable supposed to extend Value and always smash other stuff to its own type? If so, maybe this,

    protocol Value {
    protocol Value : Equatable {
    }

    protocol Smashable {
    typealias V : Value
    func valueBySmashingOtherValue(someOtherValue: Value) -> V
    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) -> Bar {
    return Bar()
    func valueBySmashingOtherValue<SomeOtherValue : Value>(val: SomeOtherValue) -> Foo {
    return Foo()
    }
    }
    func ==(lhs:Foo, rhs:Foo) -> Bool {
    return false
    }

  2. kongtomorrow revised this gist Jun 21, 2015. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,25 @@
    protocol Value {
    protocol Value : Equatable {
    }

    protocol Smashable {
    typealias TargetValue : Value
    func valueBySmashingOtherValue(someOtherValue: Value) -> TargetValue
    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) -> Bar {
    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,

  3. kongtomorrow revised this gist Jun 21, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,8 @@ protocol Value {
    }

    protocol Smashable {
    typealias V : Value
    func valueBySmashingOtherValue(someOtherValue: Value) -> V
    typealias TargetValue : Value
    func valueBySmashingOtherValue(someOtherValue: Value) -> TargetValue
    }

    struct Bar : Value {
  4. kongtomorrow revised this gist Jun 21, 2015. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -3,14 +3,14 @@ protocol Value {

    protocol Smashable {
    typealias V : Value
    func valueBySmashingOtherValue<OtherV : Value>(value: OtherV) -> V
    func valueBySmashingOtherValue(someOtherValue: Value) -> V
    }

    struct Bar : Value {
    }

    struct Foo : Value, Smashable {
    func valueBySmashingOtherValue<OtherV : Value>(value: OtherV) -> Bar {
    func valueBySmashingOtherValue(someOtherValue: Value) -> Bar {
    return Bar()
    }
    }
    @@ -20,13 +20,16 @@ struct Foo : Value, Smashable {
    protocol Value {
    }

    protocol Smashable : Value {
    func valueBySmashingOtherValue<AnyOtherValue : Value>(value: AnyOtherValue) -> Self
    protocol Smashable {
    typealias V : Value
    func valueBySmashingOtherValue(someOtherValue: Value) -> V
    }

    struct Foo : Smashable {
    func valueBySmashingOtherValue<AnyOtherValue : Value>(value: AnyOtherValue) -> Foo {
    return Foo()
    }
    struct Bar : Value {
    }

    struct Foo : Value, Smashable {
    func valueBySmashingOtherValue(someOtherValue: Value) -> Bar {
    return Bar()
    }
    }
  5. kongtomorrow revised this gist Jun 21, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,13 @@ protocol Value {

    protocol Smashable {
    typealias V : Value
    func valueBySmashingOtherValue(value: V) -> V
    func valueBySmashingOtherValue<OtherV : Value>(value: OtherV) -> V
    }

    struct Bar : Value {
    }

    struct Foo : Value {
    struct Foo : Value, Smashable {
    func valueBySmashingOtherValue<OtherV : Value>(value: OtherV) -> Bar {
    return Bar()
    }
  6. kongtomorrow revised this gist Jun 21, 2015. 1 changed file with 19 additions and 3 deletions.
    22 changes: 19 additions & 3 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -3,14 +3,30 @@ protocol Value {

    protocol Smashable {
    typealias V : Value
    func valueBySmashing​OtherValue​(value: V) -> V
    func valueBySmashingOtherValue(value: V) -> V
    }

    struct Bar : Value {
    }

    struct Foo : Value {
    func valueBySmashing​OtherValue​<OtherV : Value>(value: OtherV) -> Bar {
    func valueBySmashingOtherValue<OtherV : Value>(value: OtherV) -> Bar {
    return Bar()
    }
    }
    }

    // or actually, is Smashable supposed to extend Value and always smash other stuff to its own type? If so, maybe this,

    protocol Value {
    }

    protocol Smashable : Value {
    func valueBySmashingOtherValue<AnyOtherValue : Value>(value: AnyOtherValue) -> Self
    }

    struct Foo : Smashable {
    func valueBySmashingOtherValue<AnyOtherValue : Value>(value: AnyOtherValue) -> Foo {
    return Foo()
    }
    }

  7. kongtomorrow created this gist Jun 21, 2015.
    16 changes: 16 additions & 0 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    protocol Value {
    }

    protocol Smashable {
    typealias V : Value
    func valueBySmashing​OtherValue​(value: V) -> V
    }

    struct Bar : Value {
    }

    struct Foo : Value {
    func valueBySmashing​OtherValue​<OtherV : Value>(value: OtherV) -> Bar {
    return Bar()
    }
    }