Difference between revisions of "Phantom type"
Jump to navigation
Jump to search
(Re-word) |
|||
Line 1: | Line 1: | ||
− | A '''phantom type''' is a [[type]] |
+ | 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. |
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]]): |
||
Line 5: | Line 5: | ||
data MyType |
data MyType |
||
− | This |
+ | This lets the compiler recognize phantom types and ensure they aren't used improperly. |
[[Category:Idioms]] |
[[Category:Idioms]] |
Revision as of 06:16, 6 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, for example.
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.