Personal tools

Empty type

From HaskellWiki

Revision as of 23:12, 31 July 2011 by Benmachine (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 no values.

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

The only value here is bottom, which is impossible to completely 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:

data Void