Thanks for those useful hints!
On Monday, February 15, 2016 at 2:49:04 PM UTC+1, Tim Holy wrote: > > True, but when you care about performance it's much better to write the > wrapper functions---the results will be inferrable, unlike manipulations > of > the parameters vector. > > For Arrays, you already have the defined function `eltype` and `ndims`. If > your > types fall into some kind of hierarchy, then you may be able to use > subtyping. > For example: > > julia> immutable MyWeirdArray{Sym,Len,T,N} <: AbstractArray{T,N} > data::NTuple{Len,T} > end > > julia> ndims(MyWeirdArray{:zero_offset, 15, Float64, 1}) > 1 > > julia> eltype(MyWeirdArray{:zero_offset, 15, Float64, 1}) > Float64 > > Both base/ julia and the ColorTypes package contain good examples of how > to go > about this kind of manipulation. > > Best, > --Tim > > On Monday, February 15, 2016 05:28:19 AM Bart Janssens wrote: > > There is the parameters field of the types, but I'm not sure if that's > > considered private. You can do > > Array{Float64, 1}.parameters[2] > > to get 1, for example. > > > > On Monday, February 15, 2016 at 2:14:35 PM UTC+1, jw3126 wrote: > > > I have an instance of a parametric type, is there a canonical way to > get > > > the parameter values? > > > For example I could have some Array{T, d} and want to know whether T > is > > > Float64 and what its dimension is. > > > The only way of doing this I am aware of is writing code like: > > > > > > dimension{T, dim}(arr::Array{T, dim}) = dim > > > numbertype{T, dim}(arr::Array{T, dim}) = T > > > > > > Is there a built-in function to do this? And maybe a way to get > parameter > > > values for arbitrary types? > > > E.g. I have some instance of MyType{S, T, U, n} is and want to know U. > Do > > > I have to repeat code like the above each time I define a new > parametric > > > type? > >