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

Suggestion: void as a first-class citizen #234

Closed
erik-kallen opened this issue Feb 4, 2015 · 6 comments
Closed

Suggestion: void as a first-class citizen #234

erik-kallen opened this issue Feb 4, 2015 · 6 comments
Labels
Area-Language Design Feature Request Language-C# Resolution-External The behavior lies outside the functionality covered by this repository

Comments

@erik-kallen
Copy link

I don't know if this is possible, but I find that it would often be useful to be allowed to use void as a normal type (which I think is commonly called unit in functional languages).

This means, for example, that delegating methods can look the same whether they return void or not (note that M1 and M2 have syntactically identical definitions):

class C {
    C _wrapped;

    public void M1(int a) {
        return _wrapped.M1(a);
    }

    public int M2(int a) {
        return _wrapped.M2(a);
    }

    public void M3(int a) {
        var result = _wrapped.M3(a);
        DoSomethingElse();
        return result;
    }
}

Especially when doing code generation, this becomes an issue at times.

Bonus points if it would also be possible to treat an Action<T> as equivalent to Func<T, void>.

@sharwell
Copy link
Member

sharwell commented Feb 4, 2015

This is not a duplicate of #166, but that issue does contain quite a bit of discussion about this particular issue.

@BrannonKing
Copy link

There has been a few occasions where I wanted to return a void method from inside a void method. It would make for more consistent code to be able to return void.

@ryanbnl
Copy link

ryanbnl commented Feb 12, 2015

What is the relation between void and null? F# has null for interop. There must have been a reason why it wasn't replaced with unit....

@yufeih
Copy link
Contributor

yufeih commented Mar 11, 2015

Then Task will also be equivalent to Task

@ibrahimbensalah
Copy link

I really would love to see this feature in future version of C#. In my case i have a lot of utility 'duplicated' method overloads, one for Action<> and other for Func<,>.
In some case, type inference also breaks because compiler is not able to choose the right overload, altho it's probably an issue of the compiler itself.
anyhow, it would be much cleaner if Action is just an instance of Func<T, Void> where void is first class refugee ;)

@gafter
Copy link
Member

gafter commented Mar 20, 2017

We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages.

@gafter gafter closed this as completed Mar 20, 2017
@sharwell sharwell added Resolution-External The behavior lies outside the functionality covered by this repository and removed 0 - Backlog labels Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Feature Request Language-C# Resolution-External The behavior lies outside the functionality covered by this repository
Projects
None yet
Development

No branches or pull requests

9 participants