Is it possible to have struct to parametric with Val{}?

Hi All,

I wonder if I could make a parametric type like this?

struct AAA{Val{a}} 
    aaa::Bool
end

b = AAA{Val{true}}(true)

I tried a few variants all doesn’t work. Perhaps I can specalized with Val{} in struct?

Why not remove the Val?

struct AAA{B}
    aaa::Bool
end
b = AAA{true}(true)
2 Likes

yes you are right, thanks

You can also just do this if you wanted the Val for whatever reason:

julia> struct AAA{T}
           aaa :: Bool
       end

julia> b = AAA{Val{true}}(true)
AAA{Val{true}}(true)
1 Like