Copyright  (c) The University of Glasgow 2009 

License  see libraries/ghcprim/LICENSE 
Maintainer  cvsghc@haskell.org 
Stability  internal 
Portability  nonportable (GHC Extensions) 
Safe Haskell  None 
Language  Haskell2010 
GHC type definitions. Use GHC.Exts from the base package instead of importing this module directly.
Synopsis
 data Bool
 data Char = C# Char#
 data Int = I# Int#
 data Word = W# Word#
 data Float = F# Float#
 data Double = D# Double#
 data Ordering
 newtype IO a = IO (State# RealWorld > (# State# RealWorld, a #))
 data List a
 isTrue# :: Int# > Bool
 data SPEC
 data Symbol
 type family Any :: k where ...
 class a ~# b => (a :: k) ~ (b :: k)
 class a ~# b => (a :: k0) ~~ (b :: k1)
 class a ~R# b => Coercible (a :: k) (b :: k)
 data TYPE (a :: RuntimeRep)
 data CONSTRAINT (a :: RuntimeRep)
 data Levity
 data RuntimeRep
 type LiftedRep = 'BoxedRep 'Lifted
 type UnliftedRep = 'BoxedRep 'Unlifted
 type Type = TYPE LiftedRep
 type UnliftedType = TYPE UnliftedRep
 type Constraint = CONSTRAINT LiftedRep
 type ZeroBitRep = 'TupleRep ('[] :: [RuntimeRep])
 type ZeroBitType = TYPE ZeroBitRep
 data VecCount
 data VecElem
 type Void# = (# #)
 data DictBox a = a => MkDictBox
 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
 type family MultMul (a :: Multiplicity) (b :: Multiplicity) :: Multiplicity where ...
 data Module = Module TrName TrName
 data TrName
 data TyCon = TyCon Word64# Word64# Module TrName Int# KindRep
 data TypeLitSort
 data KindRep
 type KindBndr = Int
Builtin types
The character type Char
represents Unicode codespace
and its elements are code points as in definitions
D9 and D10 of the Unicode Standard.
Character literals in Haskell are singlequoted: 'Q'
, 'Я'
or 'Ω'
.
To represent a single quote itself use '\''
, and to represent a backslash
use '\\'
. The full grammar can be found in the section 2.6 of the
Haskell 2010 Language Report.
To specify a character by its code point one can use decimal, hexadecimal
or octal notation: '\65'
, '\x41'
and '\o101'
are all alternative forms
of 'A'
. The largest code point is '\x10ffff'
.
There is a special escape syntax for ASCII control characters:
Escape  Alternatives  Meaning 

'\NUL'  '\0'  null character 
'\SOH'  '\1'  start of heading 
'\STX'  '\2'  start of text 
'\ETX'  '\3'  end of text 
'\EOT'  '\4'  end of transmission 
'\ENQ'  '\5'  enquiry 
'\ACK'  '\6'  acknowledge 
'\BEL'  '\7' , '\a'  bell (alert) 
'\BS'  '\8' , '\b'  backspace 
'\HT'  '\9' , '\t'  horizontal tab 
'\LF'  '\10' , '\n'  line feed (new line) 
'\VT'  '\11' , '\v'  vertical tab 
'\FF'  '\12' , '\f'  form feed 
'\CR'  '\13' , '\r'  carriage return 
'\SO'  '\14'  shift out 
'\SI'  '\15'  shift in 
'\DLE'  '\16'  data link escape 
'\DC1'  '\17'  device control 1 
'\DC2'  '\18'  device control 2 
'\DC3'  '\19'  device control 3 
'\DC4'  '\20'  device control 4 
'\NAK'  '\21'  negative acknowledge 
'\SYN'  '\22'  synchronous idle 
'\ETB'  '\23'  end of transmission block 
'\CAN'  '\24'  cancel 
'\EM'  '\25'  end of medium 
'\SUB'  '\26'  substitute 
'\ESC'  '\27'  escape 
'\FS'  '\28'  file separator 
'\GS'  '\29'  group separator 
'\RS'  '\30'  record separator 
'\US'  '\31'  unit separator 
'\SP'  '\32' , ' '  space 
'\DEL'  '\127'  delete 
A fixedprecision integer type with at least the range [2^29 .. 2^291]
.
The exact range for a given implementation can be determined by using
minBound
and maxBound
from the Bounded
class.
Singleprecision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE singleprecision type.
Instances
Eq Float Source #  Note that due to the presence of
Also note that

Ord Float Source #  See 
Defined in GHC.Classes 
Doubleprecision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE doubleprecision type.
Instances
Eq Double Source #  Note that due to the presence of
Also note that

Ord Double Source #  IEEE 754 IEEE 7542008, section 5.11 requires that if at least one of arguments of
IEEE 7542008, section 5.10 defines Thus, users must be extremely cautious when using Moving further, the behaviour of IEEE 7542008 compliant 
Defined in GHC.Classes 
Instances
Eq Ordering Source #  
Ord Ordering Source #  
Defined in GHC.Classes 
A value of type
is a computation which, when performed,
does some I/O before returning a value of type IO
aa
.
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 donotation
or the >>
and >>=
operations from the Monad
class.
The builtin list type, usually written in its nonprefix form [a]
.
In Haskell, lists are one of the most important data types as they are often used analogous to loops in imperative programming languages. These lists are singly linked, which makes it unsuited for operations that require \(\mathcal{O}(1)\) access. Instead, lists are intended to be traversed.
Lists are constructed recursively using the rightassociative consoperator
(:) :: a > [a] > [a]
, which prepends an element to a list,
and the empty list []
.
(1 : 2 : 3 : []) == (1 : (2 : (3 : []))) == [1, 2, 3]
Internally and in memory, all the above are represented like this, with arrows being pointers to locations in memory.
╭───┬───┬──╮ ╭───┬───┬──╮ ╭───┬───┬──╮ ╭────╮ │(:)│ │ ─┼──>│(:)│ │ ─┼──>│(:)│ │ ─┼──>│ [] │ ╰───┴─┼─┴──╯ ╰───┴─┼─┴──╯ ╰───┴─┼─┴──╯ ╰────╯ v v v 1 2 3
As seen above, lists can also be constructed using list literals
of the form [x_1, x_2, ..., x_n]
which are syntactic sugar and, unless XOverloadedLists
is enabled,
are translated into uses of (:)
and []
Similarly, String
literals of the form "I 💜 hs"
are translated into
Lists of characters, ['I', ' ', '💜', ' ', 'h', 's']
.
Examples
>>> ['H', 'a', 's', 'k', 'e', 'l', 'l'] "Haskell"
>>> 1 : [4, 1, 5, 9] [1,4,1,5,9]
>>> [] : [] : [] [[],[]]
Since: ghcprim0.10.0
isTrue# :: Int# > Bool Source #
Alias for tagToEnum#
. Returns True if its parameter is 1# and False
if it is 0#.
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. For example,
instead of
loop x where loop arg = ...
write
loop SPEC x where loop !_ arg = ...
There is no semantic difference between SPEC
and SPEC2
,
we just need a type with two contructors lest it is optimised away
before SpecConstr
.
This type is reexported from GHC.Exts since GHC 9.0 and base4.15
.
For compatibility with earlier releases import it from GHC.Types
in ghcprim
package.
Since: ghcprim0.3.1.0
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 => (a :: k) ~ (b :: k) 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 => (a :: k0) ~~ (b :: k1) 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
fprintequalityrelations
is set.
In 0.7.0
, the fixity was set to infix 4
to match the fixity of :~~:
.
class a ~R# b => Coercible (a :: k) (b :: k) Source #
Coercible
is a twoparameter 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 onthefly during
typechecking. 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 basecase:
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: ghcprim0.4.0
Representation polymorphism
data TYPE (a :: RuntimeRep) Source #
data CONSTRAINT (a :: RuntimeRep) Source #
data RuntimeRep Source #
GHC maintains a property that the kind of all inhabited types
(as distinct from type constructors or typelevel 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).
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, wordsized value 
Int8Rep  signed, 8bit value 
Int16Rep  signed, 16bit value 
Int32Rep  signed, 32bit value 
Int64Rep  signed, 64bit value 
WordRep  unsigned, wordsized value 
Word8Rep  unsigned, 8bit value 
Word16Rep  unsigned, 16bit value 
Word32Rep  unsigned, 32bit value 
Word64Rep  unsigned, 64bit value 
AddrRep  A pointer, but not to a Haskell value 
FloatRep  a 32bit floating point number 
DoubleRep  a 64bit floating point number 
type UnliftedRep = 'BoxedRep 'Unlifted Source #
The runtime representation of unlifted types.
type UnliftedType = TYPE UnliftedRep Source #
The kind of boxed, unlifted values, for example Array#
or a userdefined
unlifted data type, using XUnliftedDataTypes
.
type Constraint = CONSTRAINT LiftedRep Source #
The kind of lifted constraints
type ZeroBitRep = 'TupleRep ('[] :: [RuntimeRep]) Source #
The runtime representation of a zerowidth tuple, represented by no bits at all
type ZeroBitType = TYPE ZeroBitRep Source #
The kind of the empty unboxed tuple type (# #)
Element of a SIMD vector type
Boxing constructors
Data type Dict
provides a simple way to wrap up a (lifted)
constraint as a type
a => MkDictBox 
Multiplicity types
data Multiplicity Source #
type family MultMul (a :: Multiplicity) (b :: Multiplicity) :: Multiplicity where ... Source #
Runtime type representation
The representation produced by GHC for conjuring up the kind of a
TypeRep
.