What is the right usage of where clauses to avoid these function calls?

Hi all,
Trying to write a function to extract one of the type parameters from the instance of a struct. Have it working but wondering what the syntax would be to this in one line as opposed to using the Type{…} function that I’ve implemented.

struct A{X} end

struct B{U <: A, T <: Real}
    val::T
end

struct C{V <: B}
    val::B
end


# why won't b = B{A{:foo}}(32.6) suffice?? Not clear, but mostly orthogonal to question
b = B{A{:foo}, Float64}(32.6)
c = C{B{A{:foo}, Float64}}(b)

# **given object of type C how do you find U?**
flavor(::Type{B{X, T}} where T) where X = X
flavor(::C{R}) where R = flavor(R)
# what is the equivalent one-liner? below doesn't work
# flavor(::C{R{S}}) where R where S = S

thanks in advance

Are you looking for flavor(::C{<:B{S}}) where S = S?

2 Likes

looks good, thank you.