(New page: An '''empty type''' is one that has no values. They're often used with phantom types or type arithmetic. How you define one depends on how picky you are that the type has genuinely...)
Latest revision as of 01:25, 20 January 2012
Frequently when defining a type whose values are never meant to be used, the simplest way is to just define it with a single, token value, whose constructor you don't export:
data E0 = E0
However, this is not a truly empty type, so some people find the following more satisfying:
newtype Void = Void Void
Although we do have constructors here, they do nothing (in fact, Void is essentially id) and the only value here is bottom, which is impossible to be rid of. So this is as close as we can get, except that we might regard the syntax as somewhat non-obvious. To address that concern, Haskell 2010 (or GHC with EmptyDataDecls) allows you to just not specify any constructors at all:
This is theoretically equivalent to the previous type, but saves you keyboard wear and namespace clutter.