Accessing T.parameters is almost always completely wrong. (except for TupleType: see https://github.com/JuliaLang/julia/pull/11547 for example)
For example, I've posted on a similar question previously: https://groups.google.com/d/msg/julia-users/Khe1Eh-K6i0/kxvj3day77AJ And I've written some example code of to show an example of solving this for for one particular common case: https://groups.google.com/d/msg/julia-users/NRBWq030YRE/OMIyXirmbgsJ > I'm not convinced it's more Julian to use such a helper function, since it will needlessly compile a different method for each distinct set of parameters. It's definitely more Julian to go this route. The helper function would be inlined anyways, so there's essentially no overhead to this approach. On Fri, Sep 11, 2015 at 4:10 PM Mauro <[email protected]> wrote: > The interface Matt is prototyping for Tuple{}'s > https://github.com/mbauman/Tuples.jl > could (should?) be expanded for any type-parameters. (Or does it already > work?) > > On Fri, 2015-09-11 at 21:54, David Gold <[email protected]> wrote: > > I'm not convinced it's more Julian to use such a helper function, since > it > > will needlessly compile a different method for each distinct set of > > parameters. Directly accessing the `parameter` field of the type in > > question avoids this. > > > > On Friday, September 11, 2015 at 12:30:16 PM UTC-7, Josh Langsfeld wrote: > >> > >> You can access the 'parameters' field of a type instance object. But the > >> standard Julian way to get type parameters is to just define a helper > >> function: > >> > >> typeparams{A,B}(::Type{T{A,B}}) = A,B > >> > >> On Friday, September 11, 2015 at 3:20:17 PM UTC-4, Erik Schnetter wrote: > >>> > >>> Is there a function in Julia that allows accessing the parameters of a > >>> type? > >>> > >>> For example, if I have > >>> > >>> type T{A,B} end > >>> > >>> then I'd like a way to convert `T{Int, Char}` to `(Int, Char)`. > >>> > >>> In other words, is there a way to get at the contents of `DataType` > >>> objects? > >>> > >>> Thanks, > >>> -erik > >>> > >>> -- > >>> Erik Schnetter <[email protected]> > >>> http://www.perimeterinstitute.ca/personal/eschnetter/ > >>> > >> > >
