# Changeset View

Changeset View

# Standalone View

Standalone View

# compiler/prelude/TysPrim.hs

1 | {- | 1 | {- | ||
---|---|---|---|---|---|

2 | (c) The AQUA Project, Glasgow University, 1994-1998 | 2 | (c) The AQUA Project, Glasgow University, 1994-1998 | ||

3 | 3 | | |||

4 | 4 | | |||

5 | \section[TysPrim]{Wired-in knowledge about primitive types} | 5 | \section[TysPrim]{Wired-in knowledge about primitive types} | ||

6 | -} | 6 | -} | ||

7 | 7 | | |||

8 | {-# LANGUAGE CPP #-} | 8 | {-# LANGUAGE CPP #-} | ||

9 | 9 | | |||

10 | -- | This module defines TyCons that can't be expressed in Haskell. | 10 | -- | This module defines TyCons that can't be expressed in Haskell. | ||

11 | -- They are all, therefore, wired-in TyCons. C.f module TysWiredIn | 11 | -- They are all, therefore, wired-in TyCons. C.f module TysWiredIn | ||

12 | module TysPrim( | 12 | module TysPrim( | ||

13 | tyVarList, alphaTyVars, betaTyVars, alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar, | 13 | mkTemplateTyVars, | ||

14 | alphaTyVars, betaTyVars, alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar, | ||||

14 | alphaTy, betaTy, gammaTy, deltaTy, | 15 | alphaTy, betaTy, gammaTy, deltaTy, | ||

15 | openAlphaTy, openBetaTy, openAlphaTyVar, openBetaTyVar, openAlphaTyVars, | 16 | openAlphaTy, openBetaTy, openAlphaTyVar, openBetaTyVar, openAlphaTyVars, | ||

16 | kKiVar, | 17 | kKiVar, | ||

17 | 18 | | |||

18 | -- Kind constructors... | 19 | -- Kind constructors... | ||

19 | superKindTyCon, superKind, anyKindTyCon, liftedTypeKindTyCon, | 20 | superKindTyCon, superKind, anyKindTyCon, liftedTypeKindTyCon, | ||

20 | openTypeKindTyCon, unliftedTypeKindTyCon, constraintKindTyCon, | 21 | openTypeKindTyCon, unliftedTypeKindTyCon, constraintKindTyCon, | ||

21 | 22 | | |||

▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Line(s) | |||||

200 | \subsection{Support code} | 201 | \subsection{Support code} | ||

201 | * * | 202 | * * | ||

202 | ************************************************************************ | 203 | ************************************************************************ | ||

203 | 204 | | |||

204 | alphaTyVars is a list of type variables for use in templates: | 205 | alphaTyVars is a list of type variables for use in templates: | ||

205 | ["a", "b", ..., "z", "t1", "t2", ... ] | 206 | ["a", "b", ..., "z", "t1", "t2", ... ] | ||

206 | -} | 207 | -} | ||

207 | 208 | | |||

208 | tyVarList :: Kind -> [TyVar] | 209 | mkTemplateTyVars :: [Kind] -> [TyVar] | ||

209 | tyVarList kind = [ mkTyVar (mkInternalName (mkAlphaTyVarUnique u) | 210 | mkTemplateTyVars kinds = | ||

210 | (mkTyVarOccFS (mkFastString name)) | 211 | [ mkTyVar (mkInternalName (mkAlphaTyVarUnique u) | ||

211 | noSrcSpan) kind | 212 | (mkTyVarOccFS (mkFastString name)) | ||

212 | | u <- [2..], | 213 | noSrcSpan) k | ||

213 | let name | c <= 'z' = [c] | 214 | | (k,u) <- zip kinds [2..], | ||

214 | | otherwise = 't':show u | 215 | let name | c <= 'z' = [c] | ||

215 | where c = chr (u-2 + ord 'a') | 216 | | otherwise = 't':show u | ||

216 | ] | 217 | where c = chr (u-2 + ord 'a') | ||

218 | ] | ||||

217 | 219 | | |||

218 | alphaTyVars :: [TyVar] | 220 | alphaTyVars :: [TyVar] | ||

219 | alphaTyVars = tyVarList liftedTypeKind | 221 | alphaTyVars = mkTemplateTyVars $ repeat liftedTypeKind | ||

220 | 222 | | |||

221 | betaTyVars :: [TyVar] | 223 | betaTyVars :: [TyVar] | ||

222 | betaTyVars = tail alphaTyVars | 224 | betaTyVars = tail alphaTyVars | ||

223 | 225 | | |||

224 | alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar :: TyVar | 226 | alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar :: TyVar | ||

225 | (alphaTyVar:betaTyVar:gammaTyVar:deltaTyVar:_) = alphaTyVars | 227 | (alphaTyVar:betaTyVar:gammaTyVar:deltaTyVar:_) = alphaTyVars | ||

226 | 228 | | |||

227 | alphaTys :: [Type] | 229 | alphaTys :: [Type] | ||

228 | alphaTys = mkTyVarTys alphaTyVars | 230 | alphaTys = mkTyVarTys alphaTyVars | ||

229 | alphaTy, betaTy, gammaTy, deltaTy :: Type | 231 | alphaTy, betaTy, gammaTy, deltaTy :: Type | ||

230 | (alphaTy:betaTy:gammaTy:deltaTy:_) = alphaTys | 232 | (alphaTy:betaTy:gammaTy:deltaTy:_) = alphaTys | ||

231 | 233 | | |||

232 | -- openAlphaTyVar is prepared to be instantiated | 234 | -- openAlphaTyVar is prepared to be instantiated | ||

233 | -- to a lifted or unlifted type variable. It's used for the | 235 | -- to a lifted or unlifted type variable. It's used for the | ||

234 | -- result type for "error", so that we can have (error Int# "Help") | 236 | -- result type for "error", so that we can have (error Int# "Help") | ||

235 | openAlphaTyVars :: [TyVar] | 237 | openAlphaTyVars :: [TyVar] | ||

236 | openAlphaTyVar, openBetaTyVar :: TyVar | 238 | openAlphaTyVar, openBetaTyVar :: TyVar | ||

237 | openAlphaTyVars@(openAlphaTyVar:openBetaTyVar:_) = tyVarList openTypeKind | 239 | openAlphaTyVars@(openAlphaTyVar:openBetaTyVar:_) | ||

240 | = mkTemplateTyVars $ repeat openTypeKind | ||||

238 | 241 | | |||

239 | openAlphaTy, openBetaTy :: Type | 242 | openAlphaTy, openBetaTy :: Type | ||

240 | openAlphaTy = mkTyVarTy openAlphaTyVar | 243 | openAlphaTy = mkTyVarTy openAlphaTyVar | ||

241 | openBetaTy = mkTyVarTy openBetaTyVar | 244 | openBetaTy = mkTyVarTy openBetaTyVar | ||

242 | 245 | | |||

243 | kKiVar :: KindVar | 246 | kKiVar :: KindVar | ||

244 | kKiVar = (tyVarList superKind) !! 10 | 247 | kKiVar = (mkTemplateTyVars $ repeat superKind) !! 10 | ||

245 | 248 | | |||

246 | {- | 249 | {- | ||

247 | ************************************************************************ | 250 | ************************************************************************ | ||

248 | * * | 251 | * * | ||

249 | FunTyCon | 252 | FunTyCon | ||

250 | * * | 253 | * * | ||

251 | ************************************************************************ | 254 | ************************************************************************ | ||

252 | -} | 255 | -} | ||

▲ Show 20 Lines • Show All 539 Lines • Show Last 20 Lines |