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

Allow implementation of generic methods with constraints of the form 'T :> 'U #255

Open
baronfel opened this issue Oct 20, 2016 · 8 comments

Comments

@baronfel
Copy link
Collaborator

commented Oct 20, 2016

Allow implementation of generic methods with constraints of the form 'T :> 'U [5927125]

Submitted by Gusty on 5/14/2014 12:00:00 AM
136 votes on UserVoice prior to migration

Currently this is solved as 'a = 'b.
This limitation does not exists in C# and it makes impossible to interact with some existing libraries, as in this case http://stackoverflow.com/questions/23643989/is-it-possible-to-implement-the-idbsett-interface-in-f
This will also allow to work around F#'s lack of generic (co/contra)-variance.

Original UserVoice Submission
Archived Uservoice Comments

@7sharp9

This comment has been minimized.

Copy link
Member

commented Jun 1, 2018

+1M for this one, in recent weeks Ive hit this numerous times :-(

@robkuz

This comment has been minimized.

Copy link

commented Jun 1, 2018

And this #566
and this #629

@NinoFloris

This comment has been minimized.

Copy link

commented Jun 27, 2018

Yes please, would also be immensely helpful for abstracting away asp.net core apis behind a nicer functional api.

@cartermp this is impossible to do today for say the whole DI stack as many methods are of the form <'TService, 'TImplementation when 'TImplementation :> 'TService>.

@gerardtoconnor

This comment has been minimized.

Copy link

commented Sep 7, 2018

Had this issue many times also and would welcome this change/improvement

@abelbraaksma

This comment has been minimized.

Copy link

commented Oct 11, 2018

@dsyme, are there any serious drawbacks to implementing this, or can you 'approve in principle'? I'd assume an RFC is needed.

I'd also be interested if there's a workaround available to achieve this.

@dsyme

This comment has been minimized.

Copy link
Collaborator

commented Oct 12, 2018

@abelbraaksma Here's the current situation: The constraint solver engine of F# has no ability to represent constraints of this form - constraints "T :> U" are solved to "T = U" immediately.

This doesn't block adding the feature: we could add this form of constraint and delay solving them until U is a nominal type. We would perhaps somehow have to require that the solution for U arrives earlier rather than later (at the worst you could require that it is explicit in an instantiation on each use of the generic thing, the most extreme approach)

@wallymathieu

This comment has been minimized.

Copy link

commented Jan 6, 2019

How do you mean @dsyme ? I guess this property used often in c# isn't useful in regular f# code. I guess a workaround is to write an interface in a c# assembly?

@dsyme

This comment has been minimized.

Copy link
Collaborator

commented Jan 14, 2019

@wallymathieu I've edited my comment to clarify it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.