Currying and noescape/throws

Now that currying syntax is about to be removed, I changed one of my libraries. It uses currying a lot (I don’t use it all the time, but for this library, it really helps). However, I seem to have hit a limitation, and I’m not sure if it’s intended or not. Without built-in currying syntax, it looks like we cannot use noescape and/or rethrows anymore. Would people be interested in adding this back in?

For a very simple example, consider creating a curried variant of flatMap:

func curriedFlatMap<A, B>(x: [A]) -> (@noescape A -> [B]) -> [B] {
    return { f in
        x.flatMap(f)
    }
}

or one that works with throws/rethrows:

func curriedFlatMap<A, B>(x: [A]) -> (A throws -> [B]) rethrows -> [B] {
    return { f in
        try x.flatMap(f)
    }
}

I’m not sure how to make this concept work again when using currying. I’m also not sure if it is a big deal. I would personally love to have this functionality back. Seems like it’s mostly a type-system limitation?

Chris

Yeah, these seem like bugs to be fixed.

-Joe

···

On Feb 17, 2016, at 12:58 AM, Chris Eidhof via swift-evolution <swift-evolution@swift.org> wrote:

Now that currying syntax is about to be removed, I changed one of my libraries. It uses currying a lot (I don’t use it all the time, but for this library, it really helps). However, I seem to have hit a limitation, and I’m not sure if it’s intended or not. Without built-in currying syntax, it looks like we cannot use noescape and/or rethrows anymore. Would people be interested in adding this back in?

For a very simple example, consider creating a curried variant of flatMap:

func curriedFlatMap<A, B>(x: [A]) -> (@noescape A -> [B]) -> [B] {
    return { f in
        x.flatMap(f)
    }
}

or one that works with throws/rethrows:

func curriedFlatMap<A, B>(x: [A]) -> (A throws -> [B]) rethrows -> [B] {
    return { f in
        try x.flatMap(f)
    }
}

I’m not sure how to make this concept work again when using currying. I’m also not sure if it is a big deal. I would personally love to have this functionality back. Seems like it’s mostly a type-system limitation?