Le jeudi 05 mars 2015 à 11:59 -0800, Pooya a écrit :
> Thanks for this clear explanation. If I do the following, is my
> function type still unstable? How do you compare the following
> solution to yours in terms of efficiency, style, etc?
>
> function compute_outputs(..., output2Flag)
> # do some stuff, get x, y, and z
> # compute output 1
> output1 = ...
> if output2Flag
>
> # compute output 2
> output2 = ...
> else
> output2 = SparseMatrixCSC[] # the same type as output2 when it is
> computed
> end
> return output1, output2
> end
This version indeed appears to be type-stable, so it should be quite
efficient. Users will also be able to write
a, b = compute_outputs(..., false)
or
a, = compute_outputs(..., false)
when they don't care about the second output. So it's not a bad design,
but returning a second output even when not needed isn't super
satisfying.
Thus, maybe Steven's suggestion to create two separate functions is
better. Do you have any reason to think it's not practical for your
case?
We should probably decide what's the most idiomatic solution, and
document it to ensure consistency. What do other people think?
Regards