For example, I have 4 labels for parameterizing a type:
const POOL = Union{:A, :B, :C, :D}
const CANNOT_BE_TOGETHER = (
Union{:A, :C},
Union{:B, :D}
)
There are 4 constraints on the type parameters:
- All type parameters must be in
POOL
. - The order of
A
andB
doesn’t matter. -
A
andB
cannot be the same in one instance. - Some parameters cannot appear in the mean time (as in
CANNOT_BE_TOGETHER
).
Here is my current implementation:
struct MyType{A, B}
values::Matrix
function MyType{A, B}(values) where {A, B}
Union{A, B} in POOL || error("Unrecognized label!")
A == B && error("$A and $B can't be the same!")
Union{A, B} in CANNOT_BE_TOGETHER && error("$A and $B cannot appear together!")
new(values)
end
end
Is there a simpler, or more elegant way of specifying this? Thank you!