ghc-prim-0.10.0: GHC primitives

Copyright | (c) The University of Glasgow 2009
License | see libraries/ghc-prim/LICENSE
Maintainer | cvs-ghc@haskell.org
Stability | internal
Portability | non-portable (GHC Extensions)
Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Types

Contents

- Built-in types
- Type equality
- Representation polymorphism
- Boxing constructors
- Multiplicity types
- Runtime type representation

Description

GHC type definitions. Use GHC.Exts from the base package instead of importing this module directly.

Synopsis

- data Bool
  - = False
  - | True
- data Char = C# Char#
- data Int = I# Int#
- data Word = W# Word#
- data Float = F# Float#
- data Double = D# Double#
- data Ordering
  - = LT
  - | EQ
  - | GT
- newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #))
- data List a
- isTrue# :: Int# -> Bool
- data SPEC
  - = SPEC
  - | SPEC2
- data Symbol
- type family Any :: k where ...
- class a ~ b
- class a ~~ b
- class Coercible (a :: k) (b :: k)
- data TYPE (a :: RuntimeRep)
- data CONSTRAINT (a :: RuntimeRep)
- data Levity
  - = Lifted
  - | Unlifted
- data RuntimeRep
  - = VecRep VecCount VecElem
  - | TupleRep [RuntimeRep]
  - | SumRep [RuntimeRep]
  - | BoxedRep Levity
  - | IntRep
  - | Int8Rep
  - | Int16Rep
  - | Int32Rep
  - | Int64Rep
  - | WordRep
  - | Word8Rep
  - | Word16Rep
  - | Word32Rep
  - | Word64Rep
  - | AddrRep
  - | FloatRep
  - | DoubleRep
- type LiftedRep = 'BoxedRep 'Lifted
- type UnliftedRep = 'BoxedRep 'Unlifted
- type Type = TYPE LiftedRep
- type UnliftedType = TYPE UnliftedRep
- type Constraint = CONSTRAINT LiftedRep
- type ZeroBitRep = 'TupleRep '[]
- type ZeroBitType = TYPE ZeroBitRep
- data VecCount
  - = Vec2
  - | Vec4
  - | Vec8
  - | Vec16
  - | Vec32
  - | Vec64
- data VecElem
  - = Int8ElemRep
  - | Int16ElemRep
  - | Int32ElemRep
  - | Int64ElemRep
  - | Word8ElemRep
  - | Word16ElemRep
  - | Word32ElemRep
  - | Word64ElemRep
  - | FloatElemRep
  - | DoubleElemRep
- type Void# = (# #)
- data DictBox c where
  - MkDictBox :: c => DictBox c
- data WordBox (a :: TYPE WordRep) = MkWordBox a
- data IntBox (a :: TYPE IntRep) = MkIntBox a
- data FloatBox (a :: TYPE FloatRep) = MkFloatBox a
- data DoubleBox (a :: TYPE DoubleRep) = MkDoubleBox a
- data Multiplicity
  - = Many
  - | One
- type family MultMul (a :: Multiplicity) (b :: Multiplicity) :: Multiplicity where ...
- data Module = Module TrName TrName
- data TrName
  - = TrNameS Addr#
  - | TrNameD [Char]
- data TyCon = TyCon Word64# Word64# Module TrName Int# KindRep
- data TypeLitSort
  - = TypeLitSymbol
  - | TypeLitNat
  - | TypeLitChar
- data KindRep
  - = KindRepTyConApp TyCon [KindRep]
  - | KindRepVar !KindBndr
  - | KindRepApp KindRep KindRep
  - | KindRepFun KindRep KindRep
  - | KindRepTYPE !RuntimeRep
  - | KindRepTypeLitS TypeLitSort Addr#
  - | KindRepTypeLitD TypeLitSort [Char]
- type KindBndr = Int

# Built-in types

data Bool Source #

Constructors

False |
True |

#### Instances

Instances details

Eq Bool Source # |
Instance details Defined in GHC.Classes Methods (==) :: Bool -> Bool -> Bool Source # (/=) :: Bool -> Bool -> Bool Source #
Ord Bool Source # |
Instance details Defined in GHC.Classes Methods compare :: Bool -> Bool -> Ordering Source # (<) :: Bool -> Bool -> Bool Source # (<=) :: Bool -> Bool -> Bool Source # (>) :: Bool -> Bool -> Bool Source # (>=) :: Bool -> Bool -> Bool Source # max :: Bool -> Bool -> Bool Source # min :: Bool -> Bool -> Bool Source #

data Char Source #

The character type `Char` is an enumeration whose values represent Unicode (or equivalently ISO/IEC 10646) code points (i.e. characters, see http://www.unicode.org/ for details). This set extends the ISO 8859-1 (Latin-1) character set (the first 256 characters), which is itself an extension of the ASCII character set (the first 128 characters). A character literal in Haskell has type `Char`.

To convert a `Char` to or from the corresponding `Int` value defined by Unicode, use `toEnum` and `fromEnum` from the `Enum` class respectively (or equivalently `ord` and `chr`).

Constructors

C# Char# |

#### Instances

Instances details

Eq Char Source # |
Instance details Defined in GHC.Classes Methods (==) :: Char -> Char -> Bool Source # (/=) :: Char -> Char -> Bool Source #
Ord Char Source # |
Instance details Defined in GHC.Classes Methods compare :: Char -> Char -> Ordering Source # (<) :: Char -> Char -> Bool Source # (<=) :: Char -> Char -> Bool Source # (>) :: Char -> Char -> Bool Source # (>=) :: Char -> Char -> Bool Source # max :: Char -> Char -> Char Source # min :: Char -> Char -> Char Source #

data Int Source #

A fixed-precision integer type with at least the range `[-2^29 .. 2^29-1]`. The exact range for a given implementation can be determined by using `minBound` and `maxBound` from the `Bounded` class.

Constructors

I# Int# |

#### Instances

Instances details

Eq Int Source # |
Instance details Defined in GHC.Classes Methods (==) :: Int -> Int -> Bool Source # (/=) :: Int -> Int -> Bool Source #
Ord Int Source # |
Instance details Defined in GHC.Classes Methods compare :: Int -> Int -> Ordering Source # (<) :: Int -> Int -> Bool Source # (<=) :: Int -> Int -> Bool Source # (>) :: Int -> Int -> Bool Source # (>=) :: Int -> Int -> Bool Source # max :: Int -> Int -> Int Source # min :: Int -> Int -> Int Source #

data Word Source #

A `Word` is an unsigned integral type, with the same size as `Int`.

Constructors

W# Word# |

#### Instances

Instances details

Eq Word Source # |
Instance details Defined in GHC.Classes Methods (==) :: Word -> Word -> Bool Source # (/=) :: Word -> Word -> Bool Source #
Ord Word Source # |
Instance details Defined in GHC.Classes Methods compare :: Word -> Word -> Ordering Source # (<) :: Word -> Word -> Bool Source # (<=) :: Word -> Word -> Bool Source # (>) :: Word -> Word -> Bool Source # (>=) :: Word -> Word -> Bool Source # max :: Word -> Word -> Word Source # min :: Word -> Word -> Word Source #

data Float Source #

Single-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE single-precision type.

Constructors

F# Float# |

#### Instances

Instances details

Eq Float Source #

Note that due to the presence of `NaN`, `Float`'s `Eq` instance does not satisfy reflexivity.

    >>> 0/0 == (0/0 :: Float)
    False

Also note that `Float`'s `Eq` instance does not satisfy extensionality:

    >>> 0 == (-0 :: Float)
    True
    >>> recip 0 == recip (-0 :: Float)
    False

Instance details Defined in GHC.Classes Methods (==) :: Float -> Float -> Bool Source # (/=) :: Float -> Float -> Bool Source #

Ord Float Source #

Note that due to the presence of `NaN`, `Float`'s `Ord` instance does not satisfy reflexivity.

    >>> 0/0 <= (0/0 :: Float)
    False

Also note that, due to the same, `Ord`'s operator interactions are not respected by `Float`'s instance:

    >>> (0/0 :: Float) > 1
    False
    >>> compare (0/0 :: Float) 1
    GT

Instance details Defined in GHC.Classes Methods compare :: Float -> Float -> Ordering Source # (<) :: Float -> Float -> Bool Source # (<=) :: Float -> Float -> Bool Source # (>) :: Float -> Float -> Bool Source # (>=) :: Float -> Float -> Bool Source # max :: Float -> Float -> Float Source # min :: Float -> Float -> Float Source #

data Double Source #

Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.

Constructors

D# Double# |

#### Instances

Instances details

Eq Double Source #

Note that due to the presence of `NaN`, `Double`'s `Eq` instance does not satisfy reflexivity.

    >>> 0/0 == (0/0 :: Double)
    False

Also note that `Double`'s `Eq` instance does not satisfy substitutivity:

    >>> 0 == (-0 :: Double)
    True
    >>> recip 0 == recip (-0 :: Double)
    False

Instance details Defined in GHC.Classes Methods (==) :: Double -> Double -> Bool Source # (/=) :: Double -> Double -> Bool Source #

Ord Double Source #

Note that due to the presence of `NaN`, `Double`'s `Ord` instance does not satisfy reflexivity.

    >>> 0/0 <= (0/0 :: Double)
    False

Also note that, due to the same, `Ord`'s operator interactions are not respected by `Double`'s instance:

    >>> (0/0 :: Double) > 1
    False
    >>> compare (0/0 :: Double) 1
    GT

Instance details Defined in GHC.Classes Methods compare :: Double -> Double -> Ordering Source # (<) :: Double -> Double -> Bool Source # (<=) :: Double -> Double -> Bool Source # (>) :: Double -> Double -> Bool Source # (>=) :: Double -> Double -> Bool Source # max :: Double -> Double -> Double Source # min :: Double -> Double -> Double Source #

data Ordering Source #

Constructors

LT |
EQ |
GT |

#### Instances

Instances details

Eq Ordering Source # |
Instance details Defined in GHC.Classes Methods (==) :: Ordering -> Ordering -> Bool Source # (/=) :: Ordering -> Ordering -> Bool Source #
Ord Ordering Source # |
Instance details Defined in GHC.Classes Methods compare :: Ordering -> Ordering -> Ordering Source # (<) :: Ordering -> Ordering -> Bool Source # (<=) :: Ordering -> Ordering -> Bool Source # (>) :: Ordering -> Ordering -> Bool Source # (>=) :: Ordering -> Ordering -> Bool Source # max :: Ordering -> Ordering -> Ordering Source # min :: Ordering -> Ordering -> Ordering Source #

newtype IO a Source #

A value of type ``IO` a` is a computation which, when performed, does some I/O before returning a value of type `a`.

There is really only one way to "perform" an I/O action: bind it to `Main.main` in your program. When your program is run, the I/O will be performed. It isn't possible to perform I/O from an arbitrary function, unless that function is itself in the `IO` monad and called at some point, directly or indirectly, from `Main.main`.

`IO` is a monad, so `IO` actions can be combined using either the do-notation or the `>>` and `>>=` operations from the `Monad` class.

Constructors

IO (State# RealWorld -> (# State# RealWorld, a #)) |

data List a Source #

The builtin list type, usually written in its non-prefix form `[a]`.

#### Examples

Expand

Unless the OverloadedLists extension is enabled, list literals are syntactic sugar for repeated applications of `:` and `[]`.

    >>> 1:2:3:4:[] == [1,2,3,4]
    True

Similarly, unless the OverloadedStrings extension is enabled, string literals are syntactic sugar for a lists of characters.

    >>> ['h','e','l','l','o'] == "hello"
    True

#### Instances

Instances details

Eq a => Eq [a] Source # |
Instance details Defined in GHC.Classes Methods (==) :: [a] -> [a] -> Bool Source # (/=) :: [a] -> [a] -> Bool Source #
Ord a => Ord [a] Source # |
Instance details Defined in GHC.Classes Methods compare :: [a] -> [a] -> Ordering Source # (<) :: [a] -> [a] -> Bool Source # (<=) :: [a] -> [a] -> Bool Source # (>) :: [a] -> [a] -> Bool Source # (>=) :: [a] -> [a] -> Bool Source # max :: [a] -> [a] -> [a] Source # min :: [a] -> [a] -> [a] Source #

isTrue# :: Int# -> Bool Source #

Alias for `tagToEnum#`. Returns True if its parameter is 1# and False if it is 0#.

data SPEC Source #

`SPEC` is used by GHC in the `SpecConstr` pass in order to inform the compiler when to be particularly aggressive. In particular, it tells GHC to specialize regardless of size or the number of specializations. However, not all loops fall into this category.

Libraries can specify this by using `SPEC` data type to inform which loops should be aggressively specialized.

Constructors

SPEC |
SPEC2 |

data Symbol Source #

(Kind) This is the kind of type-level symbols.

type family Any :: k where ... Source #

The type constructor `Any` is type to which you can unsafely coerce any lifted type, and back. More concretely, for a lifted type `t` and value `x :: t`, `unsafeCoerce (unsafeCoerce x :: Any) :: t` is equivalent to `x`.

# Type equality

class a ~ b infix 4 Source #

Lifted, homogeneous equality. By lifted, we mean that it can be bogus (deferred type error). By homogeneous, the two types `a` and `b` must have the same kinds.

class a ~~ b infix 4 Source #

Lifted, heterogeneous equality. By lifted, we mean that it can be bogus (deferred type error). By heterogeneous, the two types `a` and `b` might have different kinds. Because `~~` can appear unexpectedly in error messages to users who do not care about the difference between heterogeneous equality `~~` and homogeneous equality `~`, this is printed as `~` unless `-fprint-equality-relations` is set.

In `0.7.0`, the fixity was set to `infix 4` to match the fixity of `:~~:`.

class Coercible (a :: k) (b :: k) Source #

`Coercible` is a two-parameter class that has instances for types `a` and `b` if the compiler can infer that they have the same representation. This class does not have regular instances; instead they are created on-the-fly during type-checking. Trying to manually declare an instance of `Coercible` is an error.

Nevertheless one can pretend that the following three kinds of instances exist. First, as a trivial base-case:

    instance Coercible a a

Furthermore, for every type constructor there is an instance that allows to coerce under the type constructor. For example, let `D` be a prototypical type constructor (`data` or `newtype`) with three type arguments, which have roles `nominal`, `representational` resp. `phantom`. Then there is an instance of the form

    instance Coercible b b' => Coercible (D a b c) (D a b' c')

Note that the `nominal` type arguments are equal, the `representational` type arguments can differ, but need to have a `Coercible` instance themself, and the `phantom` type arguments can be changed arbitrarily.

The third kind of instance exists for every `newtype NT = MkNT T` and comes in two variants, namely

    instance Coercible a T => Coercible a NT

    instance Coercible T b => Coercible NT b

This instance is only usable if the constructor `MkNT` is in scope.

If, as a library author of a type constructor like `Set a`, you want to prevent a user of your module to write `coerce :: Set T -> Set NT`, you need to set the role of `Set`'s type parameter to `nominal`, by writing

    type role Set nominal

For more details about this feature, please refer to Safe Coercions by Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones and Stephanie Weirich.

Since: ghc-prim-0.4.0

# Representation polymorphism

data TYPE (a :: RuntimeRep) Source #

data CONSTRAINT (a :: RuntimeRep) Source #

data Levity Source #

Whether a boxed type is lifted or unlifted.

Constructors

Lifted |
Unlifted |

data RuntimeRep Source #

GHC maintains a property that the kind of all inhabited types (as distinct from type constructors or type-level data) tells us the runtime representation of values of that type. This datatype encodes the choice of runtime value. Note that `TYPE` is parameterised by `RuntimeRep`; this is precisely what we mean by the fact that a type's kind encodes the runtime representation.

For boxed values (that is, values that are represented by a pointer), a further distinction is made, between lifted types (that contain ⊥), and unlifted ones (that don't).

Constructors

VecRep VecCount VecElem | a SIMD vector type
TupleRep [RuntimeRep] | An unboxed tuple of the given reps
SumRep [RuntimeRep] | An unboxed sum of the given reps
BoxedRep Levity | boxed; represented by a pointer
IntRep | signed, word-sized value
Int8Rep | signed, 8-bit value
Int16Rep | signed, 16-bit value
Int32Rep | signed, 32-bit value
Int64Rep | signed, 64-bit value
WordRep | unsigned, word-sized value
Word8Rep | unsigned, 8-bit value
Word16Rep | unsigned, 16-bit value
Word32Rep | unsigned, 32-bit value
Word64Rep | unsigned, 64-bit value
AddrRep | A pointer, but not to a Haskell value
FloatRep | a 32-bit floating point number
DoubleRep | a 64-bit floating point number

type LiftedRep = 'BoxedRep 'Lifted Source #

The runtime representation of lifted types.

type UnliftedRep = 'BoxedRep 'Unlifted Source #

The runtime representation of unlifted types.

type Type = TYPE LiftedRep Source #

The kind of types with lifted values. For example `Int :: Type`.

type UnliftedType = TYPE UnliftedRep Source #

The kind of boxed, unlifted values, for example `Array#` or a user-defined unlifted data type, using `-XUnliftedDataTypes`.

type Constraint = CONSTRAINT LiftedRep Source #

The kind of lifted constraints

type ZeroBitRep = 'TupleRep '[] Source #

The runtime representation of a zero-width tuple, represented by no bits at all

type ZeroBitType = TYPE ZeroBitRep Source #

The kind of the empty unboxed tuple type (# #)

data VecCount Source #

Length of a SIMD vector type

Constructors

Vec2 |
Vec4 |
Vec8 |
Vec16 |
Vec32 |
Vec64 |

data VecElem Source #

Element of a SIMD vector type

Constructors

Int8ElemRep |
Int16ElemRep |
Int32ElemRep |
Int64ElemRep |
Word8ElemRep |
Word16ElemRep |
Word32ElemRep |
Word64ElemRep |
FloatElemRep |
DoubleElemRep |

type Void# = (# #) Source #

Deprecated: Void# is now an alias for the unboxed tuple (# #).

# Boxing constructors

data DictBox c where Source #

Data type `Dict` provides a simple way to wrap up a (lifted) constraint as a type

Constructors

MkDictBox :: c => DictBox c |

data WordBox (a :: TYPE WordRep) Source #

Constructors

MkWordBox a |

data IntBox (a :: TYPE IntRep) Source #

Constructors

MkIntBox a |

data FloatBox (a :: TYPE FloatRep) Source #

Constructors

MkFloatBox a |

data DoubleBox (a :: TYPE DoubleRep) Source #

Constructors

MkDoubleBox a |

# Multiplicity types

data Multiplicity Source #

Constructors

Many |
One |

type family MultMul (a :: Multiplicity) (b :: Multiplicity) :: Multiplicity where ... Source #

Equations

MultMul 'One x = x |
MultMul x 'One = x |
MultMul 'Many x = 'Many |
MultMul x 'Many = 'Many |

# Runtime type representation

data Module Source #

Constructors

Module |

Fields

- TrName

  Package name

- TrName

  Module name

#### Instances

Instances details

Eq Module Source # |
Instance details Defined in GHC.Classes Methods (==) :: Module -> Module -> Bool Source # (/=) :: Module -> Module -> Bool Source #

data TrName Source #

Constructors

TrNameS Addr# | Static
TrNameD [Char] | Dynamic

#### Instances

Instances details

Eq TrName Source # |
Instance details Defined in GHC.Classes Methods (==) :: TrName -> TrName -> Bool Source # (/=) :: TrName -> TrName -> Bool Source #

data TyCon Source #

Constructors

TyCon |

Fields

- Word64#

  Fingerprint (high)

- Word64#

  Fingerprint (low)

- Module

  Module in which this is defined

- TrName

  Type constructor name

- Int#

  How many kind variables do we accept?

- KindRep

  A representation of the type's kind

#### Instances

Instances details

Eq TyCon Source # |
Instance details Defined in GHC.Classes Methods (==) :: TyCon -> TyCon -> Bool Source # (/=) :: TyCon -> TyCon -> Bool Source #
Ord TyCon Source # |
Instance details Defined in GHC.Classes Methods compare :: TyCon -> TyCon -> Ordering Source # (<) :: TyCon -> TyCon -> Bool Source # (<=) :: TyCon -> TyCon -> Bool Source # (>) :: TyCon -> TyCon -> Bool Source # (>=) :: TyCon -> TyCon -> Bool Source # max :: TyCon -> TyCon -> TyCon Source # min :: TyCon -> TyCon -> TyCon Source #

data TypeLitSort Source #

Constructors

TypeLitSymbol |
TypeLitNat |
TypeLitChar |

data KindRep Source #

The representation produced by GHC for conjuring up the kind of a `TypeRep`.

Constructors

KindRepTyConApp TyCon [KindRep] |
KindRepVar !KindBndr |
KindRepApp KindRep KindRep |
KindRepFun KindRep KindRep |
KindRepTYPE !RuntimeRep |
KindRepTypeLitS TypeLitSort Addr# |
KindRepTypeLitD TypeLitSort [Char] |

type KindBndr = Int Source #

A de Bruijn index for a binder within a `KindRep`.