-
Notifications
You must be signed in to change notification settings - Fork 143
add FS-1331 - Allow opens in type and expression scopes #810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| ```fsharp | ||
| type C() = | ||
| do printfn "%d" Int32.MaxValue // <- Cannot find the `Int32` here | ||
| open System |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be considered an expressions-scoped open and NOT be valid in the member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original suggestion doesn't mentioned this, but I think the contents opened in type should be valid in members.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense. I was somehow thinking of an open inside the do body. Good that you added the extra example above for it.
|
|
||
| # Drawbacks | ||
|
|
||
| TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any foreseen deviations from a module level open ? I assume those can arise from the implementation.
If yes, I would like to have them listed here (inconsistency being the drawback).
| let! x = Async.Sleep 1000 | ||
| return x | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Lambdas ?
[ 1..10 ]
|> List.iter (fun x ->
open System
Console.WriteLine($"Value: {x}"))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lambda is ok
| This feature is only available in implementation files. | ||
|
|
||
| ```fsharp | ||
| type C() = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please add some samples about ?
type IFace =
abstract F : int -> int
open System
member _.F _ = 3
{ new IFace with
open System
member _.F _ = 3
}
type C () =
member _.F () = 3
open System
member _.F _ = 3
open System
interface IFace with
open System
member _.F _ = 3
type A =
| A
open System
member _.F _ = 3
and B =
| B
open System
member _.F _ = 3
type U =
| A
| B
open System
member _.F _ = 3
type R =
open System
{ A : int }
open System
member _.F _ = 3There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opens in types can only be on the beginning of the type definition due to the complexity of making it can applied to member/val/interface ... with following the up-to-down order.
Object expressions and interface ... with cannot contain opens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine with the feature shipping, with none of the places @edgarfgp showcased, being supported; and giving more room for consideration about the samples and in-type-definition semantics.
Ideally, it could be used in a do block at type level, let bindings, and in members themselves (under the member implemention block, not in between in stuff like properties).
|
It looks like Edit: actually it is present in the examples. Still, I think a mention in the text would be welcome. |
|
Can a section "Changes to the F# spec" be added? |
|
That makes sense. I will re-review once spec changes are added. |
Click “Files changed” → “⋯” → “View file” for the rendered RFC.