Re: [swift-evolution] [Proposal] Typed throws

2017-02-22 Thread Anton Zhilin via swift-evolution
As a follow-up, here is code that you can test now. It demonstrates the same, but with normal function result. func createArbitrary(usingGenerator f: () -> (T)) -> T { let any: Any = 42 as Any if Int.self is T.Type { let t = any as! T return t } return f() } print(c

Re: [swift-evolution] [Proposal] Typed throws

2017-02-22 Thread Anton Zhilin via swift-evolution
I understand how parametric polymorphism works *in Haskell*. But we talk about Swift, and there *is* a way to get an instance of E. I’ll explain it another way: func bypassRethrows(_ f: () throws(E) -> ()) throws(E) { let error: Error = MyError() // create an instance of `MyError` if MyEr

Re: [swift-evolution] [Proposal] Typed throws

2017-02-22 Thread Matthew Johnson via swift-evolution
> On Feb 22, 2017, at 7:10 AM, Anton Zhilin wrote: > > How about this: > > func bypassRethrows(_ f: () throws(E) -> ()) throws(E) { > if let e = (MyError() as Error) as? E { > throw e > } > } > I obviously can’t “test” this right now, but should work? > > No because there are

Re: [swift-evolution] [Proposal] Typed throws

2017-02-22 Thread Anton Zhilin via swift-evolution
How about this: func bypassRethrows(_ f: () throws(E) -> ()) throws(E) { if let e = (MyError() as Error) as? E { throw e } } I obviously can’t “test” this right now, but should work? 2017-02-22 3:42 GMT+03:00 Colin Barrett : On Sun, Feb 19, 2017 at 2:34 PM Anton Zhilin via swift

Re: [swift-evolution] [Proposal] Typed throws

2017-02-21 Thread Colin Barrett via swift-evolution
On Sun, Feb 19, 2017 at 2:34 PM Anton Zhilin via swift-evolution < swift-evolution@swift.org> wrote: > Now that I think about it, generic throws does not exactly cover rethrows. > Firstly, rethrows has semantic information that function itself does not > throw—it would be lost. > That's not true.

Re: [swift-evolution] [Proposal] Typed throws

2017-02-21 Thread Matthew Johnson via swift-evolution
Sent from my iPhone > On Feb 20, 2017, at 5:51 PM, Anton Zhilin wrote: > > 2017-02-21 1:21 GMT+03:00 Matthew Johnson : >> >> Thanks for the links. I scanned through them somewhat quickly and didn’t >> see anything that specifically said `Never` should conform to all protocols. >> Did you

Re: [swift-evolution] [Proposal] Typed throws

2017-02-20 Thread Anton Zhilin via swift-evolution
2017-02-21 1:21 GMT+03:00 Matthew Johnson : > > Thanks for the links. I scanned through them somewhat quickly and didn’t > see anything that specifically said `Never` should conform to all > protocols. Did you see that specifically? I only saw mentions of it being > a bottom type and therefore a

Re: [swift-evolution] [Proposal] Typed throws

2017-02-20 Thread Matthew Johnson via swift-evolution
> On Feb 20, 2017, at 11:14 AM, Anton Zhilin wrote: > > 2017-02-20 18:23 GMT+03:00 Matthew Johnson >: > > > > >> On Feb 20, 2017, at 3:58 AM, Anton Zhilin > > wrote: >> But that raises another concern. In a previous discussion, i

Re: [swift-evolution] [Proposal] Typed throws

2017-02-20 Thread Anton Zhilin via swift-evolution
I messed up with links a little bit, duplicating one of them. Here is another one. ​ ___ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/li

Re: [swift-evolution] [Proposal] Typed throws

2017-02-20 Thread Anton Zhilin via swift-evolution
2017-02-20 18:23 GMT+03:00 Matthew Johnson : > On Feb 20, 2017, at 3:58 AM, Anton Zhilin wrote: > > But that raises another concern. In a previous discussion, it was taken > for granted that Never should conform to all protocols > > Do you have a pointer to this discussion? I must have missed i

Re: [swift-evolution] [Proposal] Typed throws

2017-02-20 Thread Matthew Johnson via swift-evolution
> On Feb 20, 2017, at 3:58 AM, Anton Zhilin wrote: > > 2017-02-19 23:29 GMT+03:00 Matthew Johnson >: > > > > Thanks. There is nothing wrong with this at all. Your second `exec` would > not accept a non-throwing function because `Never` cannot conform to > `

Re: [swift-evolution] [Proposal] Typed throws

2017-02-20 Thread Anton Zhilin via swift-evolution
2017-02-19 23:29 GMT+03:00 Matthew Johnson : Thanks. There is nothing wrong with this at all. Your second `exec` would > not accept a non-throwing function because `Never` cannot conform to > `Default`. If it didn’t include the `Default` constraint it would not be > able to `throw E()`. > But t

Re: [swift-evolution] [Proposal] Typed throws

2017-02-19 Thread Matthew Johnson via swift-evolution
> On Feb 19, 2017, at 2:16 PM, Anton Zhilin wrote: > > 2017-02-19 22:59 GMT+03:00 Matthew Johnson >: > > > >> On Feb 19, 2017, at 1:32 PM, Anton Zhilin > > wrote: >> >> Now that I think about it, generic throws does not exactly c

Re: [swift-evolution] [Proposal] Typed throws

2017-02-19 Thread Anton Zhilin via swift-evolution
2017-02-19 22:59 GMT+03:00 Matthew Johnson : On Feb 19, 2017, at 1:32 PM, Anton Zhilin wrote: > > Now that I think about it, generic throws does not exactly cover rethrows. > Firstly, rethrows has semantic information that function itself does not > throw—it would be lost. > > Can you elaborate f

Re: [swift-evolution] [Proposal] Typed throws

2017-02-19 Thread Matthew Johnson via swift-evolution
> On Feb 19, 2017, at 1:32 PM, Anton Zhilin wrote: > > Now that I think about it, generic throws does not exactly cover rethrows. > Firstly, rethrows has semantic information that function itself does not > throw—it would be lost. > Can you elaborate further on what you mean by this? > Second

Re: [swift-evolution] [Proposal] Typed throws

2017-02-19 Thread Anton Zhilin via swift-evolution
2017-02-19 0:16 GMT+03:00 Martin Waitz : > > Now some bike-shedding: > I’m not really happy with the `throws(Type)` syntax, as it is too close to > function parameters. > Why exactly is `throws Type` ambiguous? > The proposal mentions `Type -> Result` as potential thrown type, but > functions canno

Re: [swift-evolution] [Proposal] Typed throws

2017-02-19 Thread Anton Zhilin via swift-evolution
Now that I think about it, generic throws does not exactly cover rethrows. Firstly, rethrows has semantic information that function itself does not throw—it would be lost. Secondly, rethrows allows a function with multiple throwing function parameters to become non-throwing iff all the arguments a

Re: [swift-evolution] [Proposal] Typed throws

2017-02-18 Thread Martin Waitz via swift-evolution
> Am 18.02.2017 um 17:37 schrieb Matthew Johnson via swift-evolution > : > > Thank you for taking the time to put this proposal together Anton! I really > want to see typed throws make it into Swift 4. This will be a very nice > feature to have. > > I noticed that you included Joe Groff’s i

Re: [swift-evolution] [Proposal] Typed throws

2017-02-18 Thread Matthew Johnson via swift-evolution
Thank you for taking the time to put this proposal together Anton! I really want to see typed throws make it into Swift 4. This will be a very nice feature to have. I noticed that you included Joe Groff’s idea of replacing `rethrows` by making every function have an error type which is by def

[swift-evolution] [Proposal] Typed throws

2017-02-18 Thread Anton Zhilin via swift-evolution
I’ve created a proposal draft, copy-pasting some parts from David Owens’ proposal. Here it is . I had to make one addition, which hasn’t been discussed yet. Look at Multiple throwing calls