That's a bit different. The empty type is only suitable for functions that never return (e.g. loop infinitely, crash the program). The type checker will prevent functions that have the empty type as a return type from returning.
The confusion is probably because "empty" can mean two things:
- What's inside the returned value. That may be why the parent suggested empty for the unit type. But that's now what "unit" means in the common parlance.
- How many possible values can be returned. Never returning means the function has zero possible return values.
I wrote this page for my own compiler that I'm working on, but I think it would be a good complement to this article. Note that the page is not that great on mobile, the extra real estate on desktop really helps.
Does anyone have a list of other similar texts?
There's:
- Geometry: Joyce's Java version of Euclid's _Elements_: https://mathcs.clarku.edu/~djoyce/java/elements/elements.htm...
- Physics: https://www.motionmountain.net/
- Chemistry: The Elements by Theodore Gray https://apps.apple.com/us/app/the-elements-by-theodore-gray/...
A nifty thing my kids enjoyed was the website version of the book, _Bembo's Zoo_ (which sadly is no longer on-line: https://soundeffects.fandom.com/wiki/Bembo%27s_Zoo_(Websites... )
If you're interested in collaborating for your classes, reach out to avik at avikdas dot com