'MetaData
describes a typeThe 'MetaData
parameters provide information about the original type.
'MetaData typename modulename packagename isnewtype
parameter | meaning |
---|---|
typename | The name of the type. For data Unicorn this is Unicorn |
modulename | The module in which this type is defined, e.g. “My.Module” |
packagename | The package in which this type is defined, e.g. “my-package” |
isnewtype | 'True if defined using newtype , 'False if defined using data |
The prime in 'MetaData
isn’t a typo and really part of the name.
'MetaData
gets this prime because it is defined in a peculiar way.
We usually define types using the keywords type
, newtype
, or data
, but there’s another way:
If we enable the DataKinds
extension in a module GHC will create a type for each constructor in the module, with the same name as that constructor.
That’s why in the documentation for 'MetaData
we see it defined as a constructor of the Meta
type.
DataKinds
will give us a type and a constructor with the same name.
When we put a prime in front of the name we tell GHC we mean the type, not the constructor.
In most cases we can also omit the prime, and GHC will figure out whether we mean the constructor on the type based on where the name appears.
The generated types DataKinds
produces don’t have any values
so their only real use is in phantom types, which is exactly how 'MetaData'
is used!
If you’re interested in learning more about DataKinds
check out this blog post on kinds.