Swift Regret: Unapplied Instance Methods

Part of the Swift Regrets series.

Once again I don’t have to write this one up, because Joe Groff already did. In a proposal. That was accepted!

Sometimes time constraints really stink.

Anyway, this one’s actually related to the previous regret. At one point SIL modeled object.process(arg) as something like type(of: object).process(object)(arg). The curried signature makes the types line up.

Fun fact: at one point proto-Swift had native syntax for curried functions. (Look way back in the repo history.)

func add(_ first: Int)(_ second: Int) -> Int {
  return first + second
}

func add(_ first: Int) -> (_ second: Int) -> Int {
  return { second in first + second }
}

We took it out because it didn’t line up with how people wrote Swift and made compilation more complicated. It was an interesting exploration, though. That left unapplied instance methods as the only built-in currying in the language. Besides not being so useful, though (again, see SE-0042), both the special currying syntax and unapplied instance methods have the same problems as bound methods, re: mutating/inout, strong capture only, and overloading. So…