2 % (c) The AQUA Project, Glasgow University, 1994-1995
4 \section[TysPrim]{Wired-in knowledge about primitive types}
6 This module tracks the ``state interface'' document, ``GHC prelude:
7 types and operations.''
10 #include "HsVersions.h"
14 import PrelFuns -- help functions, types and things
17 import AbsUniType ( applyTyCon )
22 %************************************************************************
24 \subsection[TysPrim-basic]{Basic primitive types (@Char#@, @Int#@, etc.)}
26 %************************************************************************
29 charPrimTy = applyTyCon charPrimTyCon []
30 charPrimTyCon = pcPrimTyCon charPrimTyConKey SLIT("Char#") 0 (\ [] -> CharKind)
32 intPrimTy = applyTyCon intPrimTyCon []
33 intPrimTyCon = pcPrimTyCon intPrimTyConKey SLIT("Int#") 0 (\ [] -> IntKind)
35 wordPrimTy = applyTyCon wordPrimTyCon []
36 wordPrimTyCon = pcPrimTyCon wordPrimTyConKey SLIT("Word#") 0 (\ [] -> WordKind)
38 addrPrimTy = applyTyCon addrPrimTyCon []
39 addrPrimTyCon = pcPrimTyCon addrPrimTyConKey SLIT("Addr#") 0 (\ [] -> AddrKind)
41 floatPrimTy = applyTyCon floatPrimTyCon []
42 floatPrimTyCon = pcPrimTyCon floatPrimTyConKey SLIT("Float#") 0 (\ [] -> FloatKind)
44 doublePrimTy = applyTyCon doublePrimTyCon []
45 doublePrimTyCon = pcPrimTyCon doublePrimTyConKey SLIT("Double#") 0 (\ [] -> DoubleKind)
48 %************************************************************************
50 \subsection[TysPrim-void]{The @Void#@ type}
52 %************************************************************************
54 Very similar to the @State#@ type.
56 voidPrimTy = applyTyCon voidPrimTyCon []
58 voidPrimTyCon = pcPrimTyCon voidPrimTyConKey SLIT("Void#") 0
62 %************************************************************************
64 \subsection[TysPrim-state]{The @State#@ type (and @_RealWorld@ types)}
66 %************************************************************************
69 mkStatePrimTy ty = applyTyCon statePrimTyCon [ty]
70 statePrimTyCon = pcPrimTyCon statePrimTyConKey SLIT("State#") 1
71 (\ [s_kind] -> VoidKind)
74 @_RealWorld@ is deeply magical. It {\em is primitive}, but it
77 realWorldTy = applyTyCon realWorldTyCon []
79 = pcDataTyCon realWorldTyConKey pRELUDE_BUILTIN SLIT("_RealWorld") []
80 [{-no data cons!-}] -- we tell you *nothing* about this guy
82 realWorldStatePrimTy = mkStatePrimTy realWorldTy
85 Note: the ``state-pairing'' types are not truly primitive, so they are
86 defined in \tr{TysWiredIn.lhs}, not here.
88 %************************************************************************
90 \subsection[TysPrim-arrays]{The primitive array types}
92 %************************************************************************
95 arrayPrimTyCon = pcPrimTyCon arrayPrimTyConKey SLIT("Array#") 1
96 (\ [elt_kind] -> ArrayKind)
98 byteArrayPrimTyCon = pcPrimTyCon byteArrayPrimTyConKey SLIT("ByteArray#") 0
99 (\ [] -> ByteArrayKind)
101 mutableArrayPrimTyCon = pcPrimTyCon mutableArrayPrimTyConKey SLIT("MutableArray#") 2
102 (\ [s_kind, elt_kind] -> ArrayKind)
104 mutableByteArrayPrimTyCon = pcPrimTyCon mutableByteArrayPrimTyConKey SLIT("MutableByteArray#") 1
105 (\ [s_kind] -> ByteArrayKind)
107 mkArrayPrimTy elt = applyTyCon arrayPrimTyCon [elt]
108 byteArrayPrimTy = applyTyCon byteArrayPrimTyCon []
109 mkMutableArrayPrimTy s elt = applyTyCon mutableArrayPrimTyCon [s, elt]
110 mkMutableByteArrayPrimTy s = applyTyCon mutableByteArrayPrimTyCon [s]
113 %************************************************************************
115 \subsection[TysPrim-synch-var]{The synchronizing variable type}
117 %************************************************************************
120 synchVarPrimTyCon = pcPrimTyCon synchVarPrimTyConKey SLIT("SynchVar#") 2
121 (\ [s_kind, elt_kind] -> PtrKind)
123 mkSynchVarPrimTy s elt = applyTyCon synchVarPrimTyCon [s, elt]
126 %************************************************************************
128 \subsection[TysPrim-stable-ptrs]{The stable-pointer type}
130 %************************************************************************
133 stablePtrPrimTyCon = pcPrimTyCon stablePtrPrimTyConKey SLIT("StablePtr#") 1
134 (\ [elt_kind] -> StablePtrKind)
136 mkStablePtrPrimTy ty = applyTyCon stablePtrPrimTyCon [ty]
139 %************************************************************************
141 \subsection[TysPrim-malloc-ptrs]{The ``malloc''-pointer type}
143 %************************************************************************
145 ``Malloc'' pointers provide a mechanism which will let Haskell's
146 garbage collector communicate with a {\em simple\/} garbage collector
147 in the IO world (probably \tr{malloc}, hence the name).We want Haskell
148 to be able to hold onto references to objects in the IO world and for
149 Haskell's garbage collector to tell the IO world when these references
150 become garbage. We are not aiming to provide a mechanism that could
151 talk to a sophisticated garbage collector such as that provided by a
152 LISP system (with a correspondingly complex interface); in particular,
153 we shall ignore the danger of circular structures spread across the
156 There are no primitive operations on @CHeapPtr#@s (although equality
157 could possibly be added?)
160 mallocPtrPrimTyCon = pcPrimTyCon mallocPtrPrimTyConKey SLIT("MallocPtr#") 0
161 (\ [] -> MallocPtrKind)