Skip to content

Conversation

@ijklam
Copy link
Contributor

@ijklam ijklam commented Aug 3, 2025

Click “Files changed” → “⋯” → “View file” for the rendered RFC.

```fsharp
type C() =
do printfn "%d" Int32.MaxValue // <- Cannot find the `Int32` here
open System
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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
}

Copy link
Member

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}"))

Copy link
Contributor Author

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() =
Copy link
Member

@edgarfgp edgarfgp Aug 6, 2025

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 _ = 3

Copy link
Contributor Author

@ijklam ijklam Aug 6, 2025

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.

Copy link
Contributor

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).

@Tarmil
Copy link
Contributor

Tarmil commented Aug 14, 2025

It looks like open type hasn't been considered. I think people will expect it to work, consistently with module-level open type, so the RFC should either include it, or explain why it doesn't.

Edit: actually it is present in the examples. Still, I think a mention in the text would be welcome.

@Martin521
Copy link
Contributor

Can a section "Changes to the F# spec" be added?

@T-Gro
Copy link
Contributor

T-Gro commented Aug 14, 2025

That makes sense. I will re-review once spec changes are added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants