JuliaHomotopyContinuation/HomotopyContinuation.jl

Question about the use of Tuple lower bound

Closed this issue · 2 comments

This isn't an issue per se, just curious (I am researching Julia subtyping, and we are looking into lower-bounds usages)...

Instruction(op::InstructionOp, a::T) where {T>:Tuple} =
Instruction(op, (a, nothing, nothing))
Instruction(op, a, b) = Instruction(op, (a, b, nothing))
Instruction(op, a, b, c) = Instruction(op, (a, b, c))

What is the purpose of using >: Tuple lower bound in the first method?
It seems that >: Tuple in this case does not impact multiple dispatch, and any value can be passed as a of type T>:Tuple:

julia> foo(a::T) where {T>:Tuple} = (a, nothing)
foo (generic function with 1 method)

julia> foo(5)
(5, nothing)

julia> foo((5,))
((5,), nothing)

julia> foo((5,6))
((5, 6), nothing)

If I recall correctly, I had some problem where the default constructor wasn't used anymore when I omitted the >: Tuple. But I cannot reproduce this anymore... So maybe this was due to some redefinitions coming from Revise or I just made some other mistake. The correct way would probably be to just define the functions as

 Instruction(op::InstructionOp, a::InstructionArg) = Instruction(op, (a, nothing, nothing)) 
 Instruction(op, a::InstructionArg, b::InstructionArg) = Instruction(op, (a, b, nothing)) 
 Instruction(op, a::InstructionArg, b::InstructionArg, c::InstructionArg) = Instruction(op, (a, b, c)) 

Sorry if this wasted your time

No worries, thank you very much for the swift reply!