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

zero- and one-element tuples #16313

Closed
gafter opened this issue Jan 6, 2017 · 11 comments
Closed

zero- and one-element tuples #16313

gafter opened this issue Jan 6, 2017 · 11 comments

Comments

@gafter
Copy link
Member

gafter commented Jan 6, 2017

To best align positional pattern-matching (which won't restrict the number of values being deconstructed) with tuples, please support zero-element and one-element tuple types and tuple expressions.

@AdamSpeight2008
Copy link
Contributor

Doesn't the current tuple parser require a minimum of 2 values?

@alrz
Copy link
Contributor

alrz commented Jan 7, 2017

@AdamSpeight2008 Yes.

@bbarry
Copy link

bbarry commented Jan 7, 2017

Why not align the other way, don't recognize deconstruction syntax with fewer than 2 elements?

@HaloFour
Copy link

HaloFour commented Jan 7, 2017

@gafter

I assume that this will be a post-C# 7.0 consideration?

@bbarry

Without support for conditional deconstruction of zero/one values then patterns like None() and Some(T) would be impossible.

@orthoxerox
Copy link
Contributor

@bbarry Single-value tuples are necessary for primitive wrapper types.

@dsaf
Copy link

dsaf commented Jan 9, 2017

Would leveraging it for naming primitive return values be considered an abuse?

(int id) SaveSomethingToDb(Something smth);

instead of

int SaveSomethingToDbAndReturnId(Something smth);

@HaloFour
Copy link

HaloFour commented Jan 9, 2017

I like how Swift handles "womples", they're effectively just the scalar value itself. So an Int32 is an (Int32) is an ((Int32)). This makes sense as 1, (1) and ((1)) are all the same value. Swift does not allow for naming the element of a "womple", though, which kind of makes sense.

@Richiban
Copy link

Will the zero-tuple be explicitly referred to as unit anywhere?

I'd love to see some support for this in the future, such as being able to use Func<int, ()> instead of Action<int>, for example.

@alrz
Copy link
Contributor

alrz commented Jan 31, 2017

I think the type (and literal) for unit could be () if it wasn't ambigious, but using it in place of void probably requires language support so you dont need to explicitly return ().

@jcouv
Copy link
Member

jcouv commented Sep 5, 2017

@gafter Is this tracking a compiler/API change or a language feature? If the latter, could you close or move to csharplang?

@gafter
Copy link
Member Author

gafter commented Sep 6, 2017

Issue moved to dotnet/csharplang #883 via ZenHub

@gafter gafter closed this as completed Sep 6, 2017
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

9 participants