points by cowlevel 2 days ago | 0 comments
In general it's a problem of sentinel values. Some languages let you abstract this - I think in Rust and C++ you can define an "intrusive optional" which is like optional but uses an invalid value pattern to store the not-present state. In memory it's the same as a sentinel value but the compiler forces you to unwrap it like an optional.
[–] eru 2 days ago
[–] cowlevel 1 day ago
[–] eru 1 day ago
In Haskell, the closest thing to adding 5 to an optional value would be something like:
This one leaves 'Nothing' alone, but adds 5 in case the value is present.