Tuple Type with unordered parameters

Is it possible to define a Tuple Type based only on the parameters of the Tuple and not the order? For example: Tuple{Float64, Char} == Tuple{Char, Float64} evaluates false, but I would like to create the possibility that these are identical.

For background, I have a number of Composite Types, MyTypeA, MyTypeB, ... , and I would like to define a Tuple Type that refers to specific combinations of Types:

MyCombinationA = Tuple{MyTypeA,MyTypeB,MyTypeC}
MyCombinationB = Tuple{MyTypeA,MyTypeD,MyTypeE,MyTypeF}

Ideally I could define the combination once and avoid having to write out the definition of every single permutation.

Order is pretty fundamental to the definition of Tuple, so there’s not a way to ignore order. Maybe you could use a Union{MyTypeA, MyTypeB, MyTypeC} somehow, since order isn’t significant for Union types?

1 Like

You could define a wrapper type an have an (inner) constructor that imposes a unique order for the type parameter.

Thanks for your suggestions. I tried Union{} and the only way I get the the specificity I’m looking for is like this:

CombA = Union{Tuple{TypeA,TypeB,TypeC},Tuple{TypeA,TypeC,TypeB},

which gets obnoxious quickly.
If I impose a unique order instead, how can I get julia to sort them? The docs (https://docs.julialang.org/en/v1.0/base/base/#Base.isless) suggest I should implement isless(). How do I go about doing that?

Something like

sort_Tuple(::Type{T}) where {T <: Tuple} =
    Tuple{sort(collect(fieldtypes(T)); by = String)...}


julia> sort_Tuple(Tuple{Int,Float64})

This is quite nice, thanks. I’ll go this route then.
I had to change by=String -> by=string otherwise I would get an error.