Hi I'm writing a simple polynomial module which requires addition of 
polynomials.

I have defined the addition by overloading the function + with an 
additional method:
+(p1::Poly, p2::Poly) = ...# code for the addition

I would like to use + now in a reduce call, imagine I have a list of 
polynomials [p1, p2, p3],
calling reduce(+, [p1, p2, p3]) behaves as expected, giving me a polynomial 
that's the sum of the 3

however, I would also like to cover the edge cases where there's only a 
single polynomial or no polynomial.
I would like the following behaviours, :

# reducing with a single polynomial list gives just the polynomial back
reduce(+, [p1]) 
> p1

# reducing with an empty list gives back the 0 polynomial
reduce(+, [])
> ZeroPoly

How might I add such functionality?
For the empty list case, how might I annotate the type so Julia is aware 
that [] means an empty list of polynomials rather than an empty list of Any?

Reply via email to