I’m trying to create a struct with parametric types. I want the struct to have a field of type Array{U{F}}, where U<:Unitful.Length, F<:AbstractFloat. Is there any way to have nested parametric types for structs in Julia?
# Struct definition attempt
using Unitful
julia> s = struct{U<:Unitful.Length, F<:AbstractFloat}
v::Array{U{F}}
end
ERROR: syntax: invalid type signature around REPL[22]:1
s = struct
Struct definitions don’t use assignment; you haven’t given your struct a name; You’ll have to specify the type parameters of Unitful.Length as well, as UnionAlls are not allowed in a type specification:
julia> struct STRUCT_NAME{F <: AbstractFloat, U <: Unitful.Length{F}}
v::Vector{U} # only one dimension or more needed?
end
Yup this worked, when copying over the code I had accidentally left out the STRUCT_NAME. The line U <: Unitful.Length{F} was exactly what I was looking for. Thanks!