More flexible parametric types

I think it is linked to one of my question about operation on type parameter. I don’t think it is possible to make complex operations on type parameter to explicit link E with all different type T1, T2,.... However if E appears in one of this type parameter, ( let say T1 == E or T1 = Array{N,E} then you can create an alias as proposed by @VinceNeede and rely on inner constructor to enforce its structure:

struct B{T1,T2,T3,T4}
               F1 :: T1
               F2 :: Vector{ T1 }
               F3 :: T2
               F4 :: Complex{T1}
              #default
              B(f1::T1, f2::T2, f3::T3, f4::T4) where {T1,T2,T3,T4} = error("building B{$T1,$T2,$T3,$T4}")
              # T1 <: Real
              B(f1::T1, f2::Vector{T1}, f3::Int, f4::Complex{T1}) where {T1<:Real} =  new{T1,Vector{T1},Int,Complex{T1}}(f1,f2,f3,f4)
end

S{E} = B{E,T2,T3,T4} where {T2,T3,T4}


Then you can dispatch on S{E} and the following function should work

function foo( x :: S{E} ) where E
	
end

If you don’t want to write all inner constructors for a large number of E then you can rely on generated functions.

2 Likes