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 abstract slots with generic return type instantiated at type 'unit' #25

Closed
baronfel opened this issue Oct 20, 2016 · 3 comments

Comments

@baronfel
Copy link
Contributor

baronfel commented Oct 20, 2016

Submitted by Eric Stokes on 1/8/2016 12:00:00 AM
7 votes on UserVoice prior to migration

The behavior described here is quite surprising to someone coming from other typed FP languages. The fact that a generic type parameter can't be unit makes the whole generics abstraction feel a bit leaky and hacky, which isn't great publicity, as F# actually has a lot of great ideas.

In practice this comes up when implementing type indexed values of various sorts, as an interface is an ideal and natural way to do that, and of course one often wants to have a sometype value. The compiler error is rather surprising as well, as it implies the object expression doesn't implement the interface, which of course isn't the case.

Original UserVoice Submission
Archived Uservoice Comments

@dsyme
Copy link
Collaborator

dsyme commented Oct 29, 2016

(adding old approval comment)

Approving this in principle, it would be great to fix this behavior. We will open an RFC on this in due course, though this is not yet high priority.

There are reasons for the existing behaviour due to unit v. void, as explained in the various stackoverflow topics on this question, but it should be possible to workaround those.

Don Syme, F# Language Evolution

@dsyme
Copy link
Collaborator

dsyme commented Jun 30, 2017

When implementing such a method

        override __.Eval (args) = expr

we would presumably need to emit two methods:

        override void Eval (args) = this.Eval(args); [ret]
        member FSharpUnit Eval (args) = expr

Tailcalls would be lost, because of the need to discard the "FSharpUnit" value

The logical place to add the method would be as soon as possible after type checking, so that duplicate method signature detection operates without change. There isn't a specific phase that's best for that, however, since there is no phase that "transforms" the TAST prior to duplicate method detection

Adding the method during typechecking is not possible because we may not yet have inferred that the abstract slot return type is being instantiated to "unit"

@dsyme
Copy link
Collaborator

dsyme commented Jan 9, 2023

Closing this as we won't be addressing this specific technical limitation, it is not a significant problem in practice.

@dsyme dsyme closed this as completed Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants