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

add tuple_type to the Tuple manipulation API #24312

Closed
tpapp opened this issue Oct 24, 2017 · 5 comments
Closed

add tuple_type to the Tuple manipulation API #24312

tpapp opened this issue Oct 24, 2017 · 5 comments
Labels
collections Data structures holding multiple items, e.g. sets

Comments

@tpapp
Copy link
Contributor

tpapp commented Oct 24, 2017

We have tuple_type_head and tuple_type_tail, but it would be nice to have something that is just equivalent to

tuple_type(T) = (tuple_type_head(T), tuple_type_tail(T)...)

Currently one needs to extract T.parameters, convert from the svec, deal with Vararg tuples manually, etc.

@JeffBezanson
Copy link
Member

Why is there a need to convert from svec? I also don't see how this would eliminate the need to handle Vararg tuples.

@tpapp
Copy link
Contributor Author

tpapp commented Oct 24, 2017

For type calculations, it would be useful to have an interface which extracts (Int, Float64, Char) from Tuple{Int, Float64, Char}. Using .parameters always feels like I am using an internal interface.

You are right, Vararg is an orthogonal issue.

@ararslan ararslan added the collections Data structures holding multiple items, e.g. sets label Oct 24, 2017
@cstjean
Copy link
Contributor

cstjean commented Oct 24, 2017

+1. By analogy with fieldname/fieldnames and fieldtype, it could be called fieldtypes.

@tpapp
Copy link
Contributor Author

tpapp commented Mar 4, 2018

fieldtypes(T::Type{<: Tuple}) = ntuple(i -> fieldtype(T, i), nfields(T))

does what I want.

But I am still wondering why there is no API for this: is it something I am not supposed to do, and use some kind of lispy recursion instead with the existing head/tail API?

@vtjnash
Copy link
Member

vtjnash commented Mar 5, 2018

Should be countfields not nfields, since the number may not be a known (might be Vararg), and so this might fail. But as a definition, that seems to me like a more sound definition than tuple_type_head / tuple_type_tail / tuple_type_cons. At lot of these usages seem to have been designed before the type system was able to express and handle many subtyping questions. c.f. #22051

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
collections Data structures holding multiple items, e.g. sets
Projects
None yet
Development

No branches or pull requests

5 participants