Weird Constructor Parameter Problem


#1
julia> abstract type Environment end

julia> abstract type SymTable{mutability} <: Environment end

julia> mutable struct BigSymTable{M<:Bool} <: SymTable{M}
               dict::Dict{Symbol,Any}
               BigSymTable{M}(dict::Dict{Symbol,T} = Dict{Symbol,Any}()) where T where M = new{M}(dict)
       end

julia> BigSymTable{false}()
ERROR: TypeError: BigSymTable: in M, expected M<:Bool, got Bool

What is wrong with this picture?
Thanks


#2

false (a value) is not a subtype of Bool (a type) and thus false <: Bool fails. You can drop the <: Bool part and it should be fine.


#3

Arguments to type parameters need to be types, not instances of types:


#4

That’s definitely common, but it doesn’t have to be the case. For example, in Array{Int, 2} the 2 is a value, not a type. Likewise in the OP’s case, BigSymTable{false} is a perfectly reasonable type parameter.


#5

You’re right. Sorry for the misinformation.