What About the Natural Numbers?
summary
Argues that for common discrete structures (lists, trees, indices) using naturals changes APIs: represent numbers as Z/S Nat with Arabic numerals desugared, make subtraction saturating subtraction so length(drop xs n) == length(xs) - n holds, treat division as slicing or use lazy infinity, and return Option Nat or a list of positions instead of negative sentinels. Notes Colin Runciman’s 1989 paper still matters after 30 years, shows implementations compile Nats to machine words or use thunks plus strictness analysis to make it practical.
AI-written summary · about
chapters (16)
- 0:00Introduction and personal anecdotes
- 5:20Goals and thesis of the paper
- 7:47Defining natural numbers in programming
- 10:18Representing naturals as a datatype
- 12:45Syntactic sugar for natural numbers
- 15:58Arithmetic with natural numbers
- 19:30Total and closed arithmetic systems
- 22:37Division challenges and solutions
- 25:56Introduction to laziness
- 29:02Benefits of lazy natural numbers
- 30:52API design beyond arithmetic
- 34:05Mind the gap in API design
- 36:10Implementation concerns for naturals
- 39:03Alternatives to lazy naturals
- 41:35Beyond naturals: sets and data structures
- 43:21Closing thoughts and call to action
