@sstadick wrote:
Hello! I’m new to julia and trying to get a grasp on parametric types / use it like a geric type.
Here’s the code:
struct Interval{T} start::Int stop::Int val::T end struct ScAIList{T} interval_list::Vector{Interval{T}} other_stuff::Int end function ScAIList{T}(inputs::Vector{Interval{T}})::ScAIList{T} where T input_len = length(inputs) return DataStructure(inputs, input_len) end function main() inputs = [Interval(3, 5, true), Interval(4, 10, false)] container = ScAIList{Bool}(inputs) end main()
Error message:
ERROR: MethodError: no method matching ScAIList{Bool}(::Array{Interval{Bool},1}, ::Int64) Closest candidates are: ScAIList{Bool}(::Any, ::Any, ::Any, ::Any, ::Any) where T at /home/me/.julia/dev/scailist/src/scailist.jl:15 ScAIList{Bool}(::Array{Interval{T},1}) where T at /home/me/.julia/dev/scailist/src/scailist.jl:23 ScAIList{Bool}(::Array{Interval{T},1}, ::UInt64) where T at /home/me/.julia/dev/scailist/src/scailist.jl:23 Stacktrace: [1] ScAIList{Bool}(::Array{Interval{Bool},1}) at /home/me/.julia/dev/scailist/src/scailist.jl:23 [2] top-level scope at REPL[7]:1
My outer constructor doesn’t appear to apply ‘T’ to the Interval it contains?
Posts: 4
Participants: 3