Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Type the kind of types with values?

Tags:

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?

like image 975
madgen Avatar asked Sep 24 '19 16:09

madgen


People also ask

What is value type datatype?

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.

What is the meaning of type value?

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.

What are the 3 types of data types?

Most programming languages support basic data types of integer numbers (of varying sizes), floating-point numbers (which approximate real numbers), characters and Booleans.

What are the 5 data types?

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.


2 Answers

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#.

like image 64
amalloy Avatar answered Oct 08 '22 16:10

amalloy


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)).

like image 20
madgen Avatar answered Oct 08 '22 17:10

madgen