News for hackers. Stuff that matters.
Re:Learning K programming: idiom by idiom [pdf] by SassyBird on Sunday May 12, 2024 @11:53PM (#40339653)
Going by your definition, max (x:xs) = max x (max xs) = max x (max (head xs) (tail xs)) = ... ad infinitum. The basic problem with that definition is that it only really defines max for non-empty lists, otherwise the pattern-matching against (x:xs) will throw an exception.

In mathematics maximum and minimum of a set are elements of said set. So the empty set has neither a maximum nor a minimum.

There is another pair of terms that obeys the rules you want max and min to obey: supremum and infimum: <https://en.wikipedia.org/wiki/Infimum_and_supremum>. And indeed supremum of the empty set is -inf. And infimum of the empty set is +inf. That’s because supremum and infimum of a set don’t need to belong to said set. They only need to belong to the set of bounds (upper for supremum; lower for infimum) of said set.

Re:Learning K programming: idiom by idiom [pdf] by rak1507 on Monday May 13, 2024 @05:55PM (#40348963)
It's not ad infinitum on finite lists though, that's the point. If you want that property to hold, then maximum [] has to be -inf.