Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Correct. The real evil is sentinel values.

That said, the memory layout of Maybe/Optional (assuming it can be stack allocated) will look much like what you outlined, though of course the API can be more user friendly.



> That said, the memory layout of Maybe/Optional (assuming it can be stack allocated) will look much like what you outlined, though of course the API can be more user friendly.

But it's really not. First of all, most Haskell compilers will optimize away usages of Maybe that are known to be Nothing or Just. Secondly, GHC at least uses tagged pointers for small sum types, including Maybe.


Rust will do optimisation on the layout of Option-looking data types to simplify them down to a pointer size if possible.




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

Search: