JuliaHomotopyContinuation / HomotopyContinuation.jl

A Julia package for solving systems of polynomials via homotopy continuation.
https://www.JuliaHomotopyContinuation.org
MIT License
181 stars 30 forks source link

Question about the use of Tuple lower bound #447

Closed julbinb closed 3 years ago

julbinb commented 3 years ago

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

https://github.com/JuliaHomotopyContinuation/HomotopyContinuation.jl/blob/a24d71335ce21e2f76b554fff6dda53a6b7d6e5b/src/model_kit/instructions.jl#L147-L150

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)
saschatimme commented 3 years ago

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

julbinb commented 3 years ago

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