Julian way to check for valid combination of inputs when defining function

You may want a parametric type:

struct Relation{n}
  R :: Set
end

Base.union(r1 :: Relation{n}, r2 :: Relation{n}) where n = [...]
Base.union(r1 :: Relation{n1}, r2 :: Relation{n2}) where {n1, n2} = [...]

But this may take your example too literally.

For more complicated cases, Traits may work (e.g., GitHub - mauro3/SimpleTraits.jl: Simple Traits for Julia). But it depends on exactly what the comparison is.

As for extending Base functions, there are various threads here on discourse, such as

2 Likes