-
Notifications
You must be signed in to change notification settings - Fork 3
Description
An idea for simplifying the implementation could be to have a wrapper type TypeParameters(T::Type) = TypeParameters{T}() that you can index into to get the type parameters, i.e.:
TypeParameters(Matrix{Float64})[:] === (Float64, 2)
TypeParameters(Matrix{Float64})[1] === Float64
TypeParameters(Matrix{Float64})[eltype] === Float64
TypeParameters(Matrix{Float64})[(ndims, eltype)] === (2, Float64)It may not be all that helpful since it could just make it harder for type inference and I'm not sure how much it will help the implementation, but I think it is interesting as a thought experiment.
I think a lot of concepts can map to the TypeParameters wrapper, i.e. defaults can be based around get:
get(TypeParameters(Matrix{Float32}), eltype) === Float32
# Use default value
get(TypeParameters(Matrix), eltype) === Float64
get(TypeParameters(Matrix), eltype, Float32) === Float32
# Determine if a type is specified or not
get(TypeParameters(Matrix), eltype, nothing) === nothingI'm not really sure setting/specifying parameters really fits this interface though, since setindex(TypeParameters(Matrix{Float32}), Float64, eltype) doesn't make much sense. Part of the motivation could be to try to decrease the number of functions in the interface of the package, which is a lot at this point.