I would be using these to generate functions (via @generated), so
performance and type stability are not too important. Compare to
`fieldtype`; this also returns the type of the respective object field,
which is not type stable, in particular if called in a loop.

-erik

On Sat, Sep 12, 2015 at 6:12 AM, Tim Holy <[email protected]> wrote:

> A much better way (because it's inferrable):
>
> firstparam{A,B}(::Type{MyType{A,B}}) = A
> secondparam{A,B}(::Type{MyType{A,B}}) = B
>
> --Tim
>
> On Friday, September 11, 2015 06:40:59 PM Jeffrey Sarnoff wrote:
> > julia> type MyType{A,B} end
> >
> > julia> ((MyType.parameters)...)
> > (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/

Reply via email to