Skip to content

[ENHANCEMENT] TypeParameters(Matrix{Float64})[eltype] === Float64 #10

@mtfishman

Description

@mtfishman

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) === nothing

I'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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions