Parametric type parameter calculation for supertype

question

#1

Is it possible to define a type

abstract Bar{PtrT,N} <: AbstractArray{T,N}

Such that PtrT is a Ptr{T}? i.e. I want Bar to be defined in terms of a pointer type, but have it implement the AbstractArray interface for the pointed-to type, without explicitly specifying the pointed-to type T in the parameterlist of Bar.


#2

Just use T as parameter and use Ptr{T} where you need to?


#3

The problem is Bar here comes from C++ and expects an array-like type as first parameter, not a scalar type. I was a bit disappointed this failed:

getparam{T}(::Type{Ptr{T}}) = T
type Bar{T,N} <: AbstractArray{getparam(T),N} end

It would be cool to have getparam execute when the type is instantiated with concrete parameters, instead of right away. At least if that wouldn’t cause breakage for other use cases.

I think I can still make your solution work by changing the C+±to-Julia type mapping, though.


#4

It’ll make dispatch undecidable.