Your definition isn’t quite doing what you think, because D <: Integer
is not the right condition. D <: Integer
says that D
is a type which is some subtype of Integer
, not that D
is a value whose type is <: Integer
. For example:
julia> Int <: Integer
true
julia> Int32 <: Integer
true
julia> 33 <: Integer
ERROR: TypeError: in <:, expected Type, got Int64
Stacktrace:
[1] top-level scope at none:0
Instead, you need to check the condition on D
inside an inner constructor. See Restrict type of value type parameter - #2 by Tamas_Papp for an example.