Skip to content

[FS-1037] Allow Union Constructor to deal with Flexible Types - #2382

Closed
liboz wants to merge 7 commits into
dotnet:masterfrom
liboz:working2
Closed

liboz wants to merge 7 commits into
dotnet:masterfrom
liboz:working2

Conversation

@liboz

@liboz liboz commented Feb 8, 2017 •

Copy link
Copy Markdown
Contributor

@liboz

liboz commented Feb 8, 2017

Copy link
Copy Markdown
Contributor Author

@dsyme @KevinRansom So, the one test that is failing has a specific case against this scenario. I've copied the relevant code below. I'm confused as to the benefit of allowing a function like data to work with subtyping, but not the union constructor Data especially since the function data can be defined as an alias for the union constructor let data = Data. Is there a specific problematic scenario we are trying to avoid here?

type A() = 
    member x.P = 1

type B() = 
    inherit A()
    member x.P = 1

type Data = Data of A * A


let data (x,y) = Data (x,y)
let pAA = (new A(),new A()) 
let pBB = (new B(),new B())
let pAB = (new A(),new B())
let pBA = (new B(),new A())
pBB |> Data   // not permitted (questionable)
pAB |> Data   // not permitted (questionable)
pBA |> Data   // not permitted (questionable)
pBB |> data   // permitted
pAB |> data   // permitted
pBA |> data   // permitted

@dsyme

dsyme commented Feb 8, 2017

Copy link
Copy Markdown
Contributor

@liboz I don't believe there's a specific reason to disallow this.

In theory allowing it may be a breaking change, as it allows more general types to be inferred in some situations. Normally this is not a problem but perhaps the value restriction can some into play, I'm not sure. So I'm in favor of adding this early in the F# 4.2 cycle and letting it settle.

Could you also please add tests for when the Union type is a struct, and for quotations of expressions involving Data (see quotes\test.fsx)

@KevinRansom KevinRansom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me.

@liboz

liboz commented Apr 13, 2017

Copy link
Copy Markdown
Contributor Author

@brettfo Is that pull request related to this?

@brettfo

brettfo commented Apr 13, 2017

Copy link
Copy Markdown
Member

No, and I offer my sincerest apologies. I'm an idiot and linked the wrong issue to the PR.

Sorry about that 😄

@dsyme

dsyme commented Aug 23, 2017

Copy link
Copy Markdown
Contributor

@liboz We should write an RFC for this - would you like to contribute that? thanks

@liboz

liboz commented Aug 24, 2017

Copy link
Copy Markdown
Contributor Author

@dsyme Created it here: fsharp/fslang-design#220

@dsyme dsyme changed the title Allow Union Constructor to deal with Flexible Types [ RFC FS-1037 ] Allow Union Constructor to deal with Flexible Types Dec 1, 2017
@dsyme dsyme changed the title [ RFC FS-1037 ] Allow Union Constructor to deal with Flexible Types [FS-1037] Allow Union Constructor to deal with Flexible Types Dec 1, 2017
vasily-kirichenko and others added 2 commits December 6, 2017 11:29
* No triggered completion on operators

* Check with classification data instead of stupid custom stuff

* Fix silly tests

* Feedback
@KevinRansom
KevinRansom changed the base branch from master to dev15.6 December 7, 2017 18:50
@KevinRansom

Copy link
Copy Markdown
Contributor

@dsyme ... can you take a look at this PR please?

@KevinRansom

Copy link
Copy Markdown
Contributor

@dsyme any chance you will take a look at this?

@brettfo brettfo closed this Apr 26, 2018
@brettfo

brettfo commented Apr 26, 2018

Copy link
Copy Markdown
Member

@liboz Can you rebase and retarget this PR to master?

@liboz

liboz commented Apr 27, 2018

Copy link
Copy Markdown
Contributor Author

@brettfo I did as you suggested. Can you reopen the PR?

@cartermp

Copy link
Copy Markdown
Contributor

@liboz the dev15.6 branch is deleted, which disallows us from re-opening it. Once you retarget to the master branch then it can be re-opened.

@liboz

liboz commented Apr 27, 2018

Copy link
Copy Markdown
Contributor Author

@cartermp Should I open a new PR to do that?

@cartermp

Copy link
Copy Markdown
Contributor

Yes, you can either do that or rebase and retarget this one. Either should work.

@abelbraaksma

abelbraaksma commented Jun 20, 2018 •

Copy link
Copy Markdown
Contributor

This was closed and the label removed for F# 4.5, without merge, is it dismissed or superseded? It is still linked from F# design suggestions, wondering if an update to the RFC is needed and/or re-linked to the superseding issue and/or closed if this wasn't pursued, see https://github.com/fsharp/fslang-design/blob/master/FSharp-4.5/FS-1037-subsumption-for-union-constructors.md

@cartermp

Copy link
Copy Markdown
Contributor

@abelbraaksma The RFC is updated.

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.

F# type constructor doesn't act like a function

9 participants