Difference between revisions of "Phantom type"

From HaskellWiki
Jump to navigation Jump to search
(Link to use of phantom types to check bounds statically)
Line 1: Line 1:
A '''phantom type''' is a [[type]] used only to construct other types; its values are never used. Phantom types are used in [[type arithmetic]], for example.
+
A '''phantom type''' is a [[type]] used only to construct other types;
  +
its values are never used. Phantom types are used in [[Type arithmetic]], and for
  +
[http://haskell.org/haskellwiki/Smart_constructors#Enforcing_the_constraint_statically encoding bounds checks in the type system.]
   
 
An extension to Haskell 98 supported by [[GHC]] allows you to define datatypes without any constructors (and therefore no values other than [[bottom]]):
 
An extension to Haskell 98 supported by [[GHC]] allows you to define datatypes without any constructors (and therefore no values other than [[bottom]]):

Revision as of 04:17, 26 February 2006

A phantom type is a type used only to construct other types; its values are never used. Phantom types are used in Type arithmetic, and for encoding bounds checks in the type system.

An extension to Haskell 98 supported by GHC allows you to define datatypes without any constructors (and therefore no values other than bottom):

data MyType

This lets the compiler recognize phantom types and ensure they aren't used improperly.


The term "phantom type" already has an established use. A simple case is described (somewhat messily) in [[1]]. [This] Google search lists many other uses of the term in that vein.