SE-0253: Static callables

I feel this is more naturally expressed as an overload of the ()(call) operator. Then you start to wonder about @dynamicMemberLookup as an overload of the .(dot) operator. It's a bit disappointing that C++ appears to have a more coherent story here, whereas we have a grab-bag of attributes and magic requirements.

The main issue with making it an operator, IMO, would be that Swift operators are pretty awkward and written as static member functions with the instance as a parameter. Which, in turn, you really have to wonder about.

I mean, if nobody wants to write this:

extension MyThing {
  static func () (self: MyThing, arg: String) -> Int {
    /* .. */
  }
}

Then why do we make them do it for simple things like Equatable? Why can't we write something like:

extension MyThing: Equatable {
  func == (other: MyThing) -> Bool { 
    /* ... */
  }
}

or, for callables:

extension MyThing {
  func () (arg: String) -> Int {
    /* .. */
  }
}
2 Likes