-
Notifications
You must be signed in to change notification settings - Fork 22
Description
try/with in seq expressions
C# is looking to allow yielding values in try/catch blocks in iterator methods.
As recently noted by C# users, the existing restriction that you cannot yield a value in the body of a try block with a catch clause is one that interferes with reasonable code refactoring. The restriction does not make the compiler any easier. Rather it was added to align with the conceptual model that the caller's loop is logically "called" at the point of the
yield
. But that is not how people think of the construct, and the restriction has little value. We propose to remove it.
I propose we also allow this in F#.
let i =
seq {
try // error FS0796: 'try'/'with' cannot be used within sequence expressions
yield 1
with _ ->
yield 2
}
Pros and Cons
The advantages of making this adjustment to F# are
- Consistency with C#
- Conciseness
- Convenience
The disadvantage of making this adjustment to F# is that this may be an already-made design decision?
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S to M
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
- This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
- I have searched both open and closed suggestions on this site and believe this is not a duplicate
- This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
- This is not a breaking change to the F# language design
- I or my company would be willing to help implement and/or test this
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.