Skip to content
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

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

Merged
merged 5 commits into from
May 24, 2018

Conversation

dsyme
Copy link
Contributor

@dsyme dsyme commented May 17, 2018

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

auduchinok commented May 17, 2018

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

dsyme commented May 17, 2018

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

dsyme commented May 17, 2018

@dotnet-bot Test Ubuntu16.04 Release_default Build please

@auduchinok
Copy link
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
Copy link
Contributor Author

dsyme commented May 18, 2018

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

dsyme commented May 19, 2018

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

dsyme commented May 22, 2018

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

dsyme commented May 22, 2018

This is now ready

@KevinRansom KevinRansom merged commit bbe06d5 into dotnet:dev15.8 May 24, 2018
KevinRansom pushed a commit to KevinRansom/fsharp that referenced this pull request May 26, 2018
…on construction and list/sequence/array yield points (dotnet#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
@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
Copy link
Contributor Author

dsyme commented May 29, 2018

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

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