3
lorentz
2y

ISO floating point numbers are essentially wrapped in a hardware-level monad because the normal meaningful values aren't closed over basic arithmetic so conceptually wrapping everything in Maybe using the 'infectious sentinel value' NaN leads to substantial speedups.

With this in mind, I think high-level languages that have a Maybe should use those and have the language-type float refer to a floating point that isn't NaN.

Comments
  • 0
    Yes, definitely. Numbers shouldn't be able to literally be not a number.
  • 1
    FWIW Rust does something similar with niche optimizations where Option<&T> and Option<NonZeroU32> are guarenteed to get compiled to a simple ptr/u32 where it's None for null/zero and Some with a non zero value otherwise
Add Comment