How do I set bounds for a parametric subtype of a parametric abstract type?

In theory, the use of Dummy{T} without explicitly declaring a “scope” for T, would mean that Dummy is an abstract type. But if I try to make an abstract type with that structure:

julia> abstract type Dummy{T} end

It works, but when I try to subtype it:

julia> struct QueCono{T}<:Dummy{T} where T<:Real
       a::Float64
       b::T
       end

I get the error:

ERROR: invalid subtyping in definition of QueCono: can only subtype data types.
Stacktrace:
 [1] top-level scope
   @ REPL[12]:1

Yeah this part of Julia syntax is sometimes tricky for me in remembering how to specify the parametric type’s bounds.

I also see your choice of a name for your subtype suggests your level of frustration :sweat_smile: in fact you’re not alone in this frustration.

As in thread I linked, the working syntax is

abstract type Dummy{T} end

struct EstoTieneSentido{T <: Real} <: Dummy{T}
    a::Float64
    b::T
end
2 Likes

Sorry, I didn’t edit the code :sweat_smile: I really appreciate your comment.

Haha, that’s okay. I’ve had a lot of frustrations learning Julia as well, they’re just much, MUCH more preferable frustrations than I’ve had with other languages. I am also personally supportive of opportunities to vent, and have constructively done so here. Another location for smaller gripings is in Slack.

Thank you for taking the time to ask your question rather than letting it go unasked. Don’t be afraid to ask other questions after doing some research on it, which I find is the best way to learn and develop skills.

And between you and me, I’ve put cusses in code as well. :stuck_out_tongue: Moreso my MATLAB code. And maybe once or twice in Julia trying to get plot recipes working in Plots.jl or Makie.jl.

Also, I took the liberty of making your question-title more specific :smiling_face:.

1 Like