Skip to content

[RFCs FS-1037, FS-1055] allow flexible inference (subsumption) at list/sequence/array yield points - #4930

Merged
KevinRansom merged 5 commits into
dotnet:dev15.8from
dsyme:fix5
May 24, 2018
Merged

KevinRansom merged 5 commits into
dotnet:dev15.8from
dsyme:fix5

Conversation

@dsyme

@dsyme dsyme commented May 17, 2018 •

Copy link
Copy Markdown
Contributor

RFC FS-1055: https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1055-subsumption-for-yield-in-sequence-expression.md

F# array and list computation expressions are great. However when you start to use yield you have to insert coercions, e.g.

let x1 : obj list  = [ yield "" :> obj ]
let x2 : seq<obj>  = seq { yield "" :> _ }

If the nominal type is known by type inference this should not be needed since the corresponding coercion is not needed for the simpler form.

let x1 : obj list  = [ yield ""  ]
let x2 : seq<obj>  = seq { yield "" }

This PR trial this language change.

RFC will follow tomorrow, I'm putting this in to run the whole test suite.

@auduchinok

auduchinok commented May 17, 2018 •

Copy link
Copy Markdown
Member

@dsyme Could this also be allowed in more places? E.g. if an expression is known to be of type of an implemented interface member.

@dsyme

dsyme commented May 17, 2018 •

Copy link
Copy Markdown
Contributor Author

@dsyme Could this also be allowed in more places? E.g. if an expression is known to be of type of an implemented interface member.

Yes, but it needs care and can in some situations be very mild breaking change (basically some things can become slightly more generic, though that's almost always not a problem). That's one thing I'm assessing.

Could you give an example please? You mean on method/property return?

@dsyme

dsyme commented May 17, 2018

Copy link
Copy Markdown
Contributor Author

@dotnet-bot Test Ubuntu16.04 Release_default Build please

@auduchinok

Copy link
Copy Markdown
Member

@dsyme Yes, both methods and properties.

/// Some external API
type IFoo =
    interface
    end

/// Some external API
type IBar =
    abstract Method: unit -> IFoo
    abstract Property: IFoo

type Foo() =
    interface IFoo

type Bar() =
    interface IBar with
        member x.Method() = Foo() :> _
        member x.Property = Foo() :> _

@dsyme

dsyme commented May 18, 2018 •

Copy link
Copy Markdown
Contributor Author

@auduchinok I've briefly looked at subsumption on the bodies of lambdas (which is my interpretation of what you're asking, or at least the natural way to implement it). This is w.r.t. subsumption based on the expected ("known") type of the lambda.

It's potentially simple but there are some additional considerations. So I don't think it's good to do in a 4.5 timeframe. Perhaps 5.0. The change above is smaller and aligns sequence expressions with list/array expressions.

The main issue is whether subsumption is for "the whole expression" or "the return points", e.g. consider

        member x.Method() = 
            if ... then 
                Foo() 
            else 
                Foo2() 

The question is really whether we allow each branch of the conditional to have independent subsumption flexibility. Likewise for the other branching constructs match, try/with.

@dsyme dsyme changed the title [RFC FS-TBD] allow flexible inference (subsumption) at list/sequence/array yield points [RFC FS-1055] allow flexible inference (subsumption) at list/sequence/array yield points May 18, 2018
@dsyme

dsyme commented May 19, 2018

Copy link
Copy Markdown
Contributor Author

This is ready. We may add #2382 into this PR, as mentioned there, or do it shortly after

@cartermp cartermp added this to the 15.8 milestone May 20, 2018
@dsyme
dsyme changed the base branch from master to dev15.8 May 21, 2018 23:39
@dsyme dsyme changed the title [RFC FS-1055] allow flexible inference (subsumption) at list/sequence/array yield points [RFCs FS-1037, FS-1055] allow flexible inference (subsumption) at union construction and list/sequence/array yield points May 22, 2018
@dsyme

dsyme commented May 22, 2018

Copy link
Copy Markdown
Contributor Author

Now also incorporates RFC https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1037-allow-union-constructors-to-deal-with-flexible-types.md via #4798

@dsyme

dsyme commented May 22, 2018

Copy link
Copy Markdown
Contributor Author

This is now ready

@KevinRansom
KevinRansom merged commit bbe06d5 into dotnet:dev15.8 May 24, 2018
@dsyme dsyme changed the title [RFCs FS-1037, FS-1055] allow flexible inference (subsumption) at union construction and list/sequence/array yield points [RFCs FS-1037, FS-1055] allow flexible inference (subsumption) at list/sequence/array yield points May 29, 2018
@dsyme

dsyme commented May 29, 2018

Copy link
Copy Markdown
Contributor Author

It looks like I didn't push the commits for the union constructors (RFC FS-1037), they are now in #5030

T-Gro pushed a commit that referenced this pull request Jun 12, 2026
…on construction and list/sequence/array yield points (#4930)

* allow flexible inference (subsumption) at list/sequence/array yield points

* allow flexible inference (subsumption) at list/sequence/array yield points

* suppress warnings for compat purposes

* fix build

* do not generalize IsCompatFlex variables to ensure code compat
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.

4 participants