This is me probably going off what is considered idiomatic in Julia, as I am clearly abusing parametric types (generic types instead of hardcoded ones) but I am struggling to understand why this doesn't work and what are my alternatives.
Say we have this parametric type {T}:
struct mystruct{T}
val::T
end
I can restrict the possibilities by supertyping T:
struct mystruct{T<:Number}
val::T
end
But I don't seem able to restrict it to a certain type:
struct mystruct{T::Int64}
val::T
end
My goal is being able to declare several fields at once by declaring the generic struct with Int64 as I did above. So I'm looking for the <: equivalent.
My end goal is to do this:
struct mystruct{T::Int64}
val::T
max::T
mystruct(val::T) = begin
new(val, typemax(T))
end
end
Instead of what I currently do:
struct mystruct
val::Int64
max::Int64
mystruct(val::Int64) = begin
new(val, typemax(val)) # or typemax(Int64)
end
end