3 ms·
With all due respect to Dr. Lamport, whose work I greatly admire, I take issue with his example of the max function. The problem he sets up is “what to do with
by sevensor 2y ago
With all due respect to Dr. Lamport, whose work I greatly admire, I take issue with his example of the max function. The problem he sets up is “what to do with an empty sequence.” He proceeds to handwave the integers and suggest that negative infinity is the right value. But in realistic use cases for max, I want to assume that it produces a finite number, and if the inputs are integral, I expect an integer to pop out.
Apologies to Lamport if he addresses this later; this is where I quit watching.
There are basically two ways out of this, that I’m aware of: either return an error, or make the initial value of the reduction explicit in the function signature, i.e.:
max(x, xs)
And not
max(xs)
- ndriscoll 2y agoI had the same thought skimming the PDF, but he does address it. One of his suggestions is to use an error value as the point at infinity. So I suppose the point is the coding looks the same, but you're taking a more principled view of what you're doing for reasoning purposes.
- tasuki 2y agoThe answer is a NonEmptySequence type. The `max` function doesn't make sense in the context of an empty sequence.
- pron 2y ago> But in realistic use cases for max, I want to assume that it produces a finite number, and if the inputs are integral, I expect an integer to pop out. But that's his point. You're talking about a concrete concern about code, whereas he says that first you should think in abstractions. Negative infinity helps you, in this case, to think in abstractions first.
- fc417fc802 2y agoAre the integers not a reasonable abstraction though?
- pron 2y agoThey could be, but using -∞ makes the abstraction simpler, and it's easy to map -∞ to an error when showing the conformance of the implementation to the abstraction.
- sevensor 2y agoThat’s my point though. Infinity isn’t useful for computation in a lot of cases where numbers are called for and it’s debatable that it even is a number. So it’s already a special error value, and if that’s the case, why use a value that accidentally behaves like a number sometimes?
- pron 2y agoBecause you're not writing a program. You're writing an abstract algorithm and this makes the algorithm slightly simpler to express without losing anything. If you don't like that, you can use a special error value instead even in your abstract description.