Hacker News new | past | comments | ask | show | jobs | submit login

Are there any plans to extend the ability so that user code can use niche values that aren't 0? Unless I failed at figuring out how to find the relevant docs, I only see NonZero formally documented but this release is clearly utilizing -1 instead (& I'm assuming it's not just doing +1/-1 math when accessing just to leverage NonZero).



Off the top of my head, I don't think there is, but not due to some objections to the feature, but because doing this is a pretty niche feature (pun absolutely intended.) Nobody has been motivated enough to do the design and consensus building work.


This came up a ton when I was doing particle filters on mobile. We had optional doubles that were initialized to NaN but NaN isn't a valid value. Being able to use optionals instead would be great (to avoid having to backtrace where an accidental NaN propagation may have started from) but the memory hit was impractical. I bet some parts of the science community might need this but the need is so spread out (each individual application) that it might not be as obvious as a popular library identifying the need.

I wish I knew language design & compiler development better & had the time to propose it & see it through.


FiniteFloat or NotNaN would be nice additions to the stdlib


NonMax types would be nice to have, since the natural "null" value for an index into some linear data structure is the highest one

In the meantime it can be done by wrapping NonZero and storing !value, but that's a (tiny) runtime overhead on each get/set




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: