If I enable MagicHash
, then I have unlifted values such as 42#
with type Int#
.
Now if Type
is the kind of types with values, then the kind of Int#
should be Type
, but it isn't because Type
is a synonym for TYPE 'LiftedRep
whereas the kind of Int#
is TYPE 'IntRep
. We can easily confirm this in ghci
,
Prelude> :set -XMagicHash -XKindSignatures
Prelude> :m +Data.Kind GHC.Prim
Prelude Data.Kind GHC.Prim> :k (Int# :: Type)
<interactive>:1:2: error:
• Expecting a lifted type, but ‘Int#’ is unlifted
• In the type ‘(Int# :: Type)’
So is it just the case that we don't regard magic literals such as 42#
as values?
A data type is a value type if it holds the data within its own memory allocation. Value types include the following: All numeric data types. Boolean , Char , and Date. All structures, even if their members are reference types.
A value type in computer programming is a coded object that involves memory allocation directly where it is created. Value types are commonly contrasted to reference types that instead act as pointers to a value that is stored elsewhere.
Most programming languages support basic data types of integer numbers (of varying sizes), floating-point numbers (which approximate real numbers), characters and Booleans.
Most modern computer languages recognize five basic categories of data types: Integral, Floating Point, Character, Character String, and composite types, with various specific subtypes defined within each broad category.
Just elide the type signature and GHCI will happily tell you:
Prelude Data.Kind GHC.Prim> :k Int#
Int# :: TYPE 'GHC.Types.IntRep
It's an unlifted Int, which is about what we'd expect from the name Int#
.
This indeed turned out to be a deficiency in the documentation and is now fixed in GHC's HEAD.
To sum up, Type
is the kind of types with lifted values because there are other values with differently kinded types such as 42# :: (Int# :: TYPE 'IntRep))
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With