Currying/Partial Application


(Jon Hull) #1

Erica’s thread on currying made me remember a (very) early discussion on the topic where currying was being removed temporarily in hopes that partial application could be added back in later with better syntax.

I would really like to be able to do the following:

  let partial = myFunc(a: 5, b: _, c: 7)
  let ans = partial(b: 6)

Thanks,
Jon


(Jeremy Pereira) #2

You can emulate it with a closure

func myFunc(a: Int, b: Int, c: Int) -> Int { return a + b + c }

let partial = { (b) -> Int in return myFunc(a: 5, b: b, c: 7) }
let ans = partial(6) // 18

It’s not ideal because you lose the argument label, but I think they’re going to fix that one day.

···

On 6 Oct 2016, at 01:50, Jonathan Hull via swift-evolution <swift-evolution@swift.org> wrote:

Erica’s thread on currying made me remember a (very) early discussion on the topic where currying was being removed temporarily in hopes that partial application could be added back in later with better syntax.

I would really like to be able to do the following:

  let partial = myFunc(a: 5, b: _, c: 7)
  let ans = partial(b: 6)

Thanks,
Jon
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution