[swift-evolution] Changing the curried static methods

Brandon Williams mbw234 at gmail.com
Mon Mar 14 09:39:50 CDT 2016


Sorry for the confusion, I’m not looking for help to model something in
particular. These are examples to show the difference between the current
curried static convention and the one I think is more expressive.

To iterate, right now CGRect.insetBy(rect)(insets) just reads incorrectly
to me. Considering that Swift aims to be expressive through method names
and argument labels, I would expect this to be CGRect.insetBy(insets)(rect).


On Sun, Mar 13, 2016 at 10:54 PM Erica Sadun <erica at ericasadun.com> wrote:

> > If static methods had their arguments flipped, we'd be able to easily
> construct functions like `CGRect.insetBy(10.0, 10.0)` and
> `CGRect.offsetBy(-20.0, 10.0)`. These are now free functions without any
> mention to a specific rectangle. We could compose them to get a function
> that simulataneously insets and translates, all without mentioning a
> rectangle. With today's static methods we'd have to apply `flip` to each
> one, i.e. `flip(CGRect.insetBy)(10.0, 10.0)`.
> >
> > This becomes very powerful with constructing data pipelines that
> describe how to transform data without ever actually mentioning the data.
> There are quite a few examples of things like this in Cocoa. A nice one is
> Core Image, in which you can build a pipeline of filters that you can feed
> images into.
> >
>
> By your description, it sort of sounds like you could want to create a
> method cascade:
>
> myRect
>    ..insetBy(args)
>    ..offsetBy(args)
>
> In this, the instance passes through each of the function calls, joining
> them into a fluent declaration
> with an implicit receiver.
>
> But it also sounds like you want to use functional chaining. Core Image
> can chain because it always has
> inputImage and outputImage and set defaults:
>
> myRect = myRect.insetBy(args).offsetBy(args)
>
> Alternative, you could be doing some kind of weird chaining thing where so
> long as the output and inputs match
> up they can be composed together:
>
> f = (x: insetByAble).insetBy(args)->(T:offsetByAble).offsetBy(args)->U
> myRect = f(myRect)
>
> But in the end, it kind of almost really sounds like you just want to
> write a function
>
> f(x: CGRect) -> CGRect {
>    x.insetBy(10.0, 10.0)
>    x.offsetBy(-20.0, 10.0)
>    return x
> }
>
> Which of these are you aiming for?
>
> -- E
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160314/a685e976/attachment.html>


More information about the swift-evolution mailing list