[swift-evolution] Move placement of 'throws' statement

Dave Abrahams dabrahams at apple.com
Wed Dec 28 12:19:07 CST 2016


on Wed Dec 28 2016, Goffredo Marocchi <swift-evolution at swift.org> wrote:

> I sense s disturbance in the force as if hundreds of pure functional
> programmers cried in anger ;).

Remember: Your focus determines your reality.

>
>> On 28 Dec 2016, at 17:52, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> 
>>> on Tue Dec 27 2016, Chris Lattner <clattner-AT-apple.com> wrote:
>>> 
>>> On Dec 26, 2016, at 2:55 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>>>>> 
>>>>> // Move `throws` to the end
>>>>> func baz() -> String throws
>>>> 
>>>> I agree that reads much better.
>>> 
>>> This doesn’t work unless you’re willing to break consistency with
>>> function type syntax, or if you’re willing to make function
>>> [type/decl] syntax ambiguous.
>>> 
>>> How would you express this, for example?
>>> 
>>>    let x : (_ a : Int) throws -> (_ b: Float) throws -> Double
>>> 
>>> it would be ambiguous to move the ‘throws’ keyword to the end of the
>>> function type, because you'd get:
>>> 
>>>    let x : (_ a : Int) -> (_ b: Float) -> Double throws throws
>> 
>> I see.  
>> 
>> We *could* say that the "throws" keyword comes after the return type
>> unless it's a function type, in which case it comes after the return
>> type's parameter list
>> 
>>       let x : (_ a : Int) -> (_ b: Float) throws -> Double throws
>> 
>> I admit this is a horrible rule from a language designer's point of view
>> but there's a chance it could end up being better for users.
>> Functions-that-return-functions are, after all, the 0.1% case.
>> 
>> -- 
>> -Dave
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-- 
-Dave



More information about the swift-evolution mailing list