Wondering if extending Base: max with max(a) = max(a...) would be safe?!

So I am wondering if

import Base: max
max(a) = max(a...)
export max

would be safe, after all I am extending the “concept” to vectors or NTuples. Bu then it may well be a rather stupid thing to do, and have serious side effects that I am unaware…

Splatting (a...) is slow for long arrays. There is maximum that does what you implement.

4 Likes

Extending Base.max in this way would be “type piracy”, which is typically a bad idea because it has side effects on unrelated code. (Aside from the fact that this is what maximum is for, or that splatting large collections is bad.)

3 Likes

reduce(max, xs) also works for this.

It’s also quite confused in terms of its own meaning. What should max([[1,2]]) be? What about max([[1,2],[3,4]])? Or max([[[1,2]]])?

This is precisely why Julia separates out the concepts of max from maximum.

And to mention the last edge case: What should max([]) (which would result in max()) be?

Presumaby the same as maximum of an empty collection, which currently throws; see also Extend the domain of maximum and minimum to include empty collection? - #3 by klacru

1 Like