I don’t know what the compiler does internally. However, I look at a signature 
like

func forEach(fn:Element throws->()) rethrows

and imagine that conceptually this exposes two overloads for this “forEach” 
function:

a)      func forEach(fn:Element->())

b)      func forEach(fn:Element throws->()) throws

In fact, I expected the swift CLI to give me an error when I attempted to 
define all three of these as functions, but no such luck.

-DW


> On Dec 21, 2015, at 7:09 PM, Jordan Rose via swift-evolution 
> <[email protected]> wrote:
> 
> John, IIRC you had some reason why this wasn't a great idea, but I can't 
> remember it. It seems useful to me too, if not something that comes up too 
> often.
> 
> Jordan
> 
>> On Dec 20, 2015, at 2:46 , Alexandre Lopoukhine via swift-evolution 
>> <[email protected] <mailto:[email protected]>> wrote:
>> 
>> Hi Dmitri,
>> 
>> This is a better example than any that I have come up with so far as to why 
>> “rethrows” should be a part of the signature. You shouldn’t have to use 
>> “try!” to apply a non-throwing function, like {print($0)} to “forEach”.
>> 
>> — Sasha
>> 
>> 
>>> On 20 Dec 2015, at 13:37, Dmitri Gribenko <[email protected] 
>>> <mailto:[email protected]>> wrote:
>>> 
>>> Hi Alexandre,
>>> 
>>> I think for this use case we don't actually need 'rethrows' to become
>>> a part of the closure type, we just need the compiler to allow and
>>> "instantiate" it in more places.
>>> 
>>> The case where we would need 'rethrows' to become a first class part
>>> of the type system is if we wanted 'rethrows' to be a part of the
>>> signature of the closure itself, for example:
>>> 
>>> (swift) let forEach = [ 10, 20, 30 ].forEach
>>> // forEach : (@noescape (Int) throws -> Void) throws -> () = (Function)
>>> 
>>> Here, a more precise type would be (@noescape (Int) throws -> Void)
>>> rethrows -> Void.
>>> 
>>> Dmitri
>>> 
>>> -- 
>>> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
>>> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <[email protected] 
>>> <mailto:[email protected]>>*/
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> [email protected] <mailto:[email protected]>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> 
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to