Changes between Version 22 and Version 23 of Commentary/Compiler/TypeType


Ignore:
Timestamp:
Jun 7, 2013 4:26:00 PM (2 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/TypeType

    v22 v23  
    6262Here, then is the representation of types (see [[GhcFile(compiler/types/TypeRep.lhs)]] for more details):
    6363{{{
    64 data Type = TyVarTy Var                         -- Type variable
     64type TyVar = Var
     65
     66data Type = TyVarTy TyVar                       -- Type variable
    6567          | AppTy Type Type                     -- Application
    6668          | TyConApp TyCon [Type]               -- Type constructor application
     
    7779A similar invariant applies to {{{FunTy}}}; {{{TyConApp}}} is never used with an arrow type.
    7880
    79 == Type variables ==
    80 
    8181Type variables are represented by the `TyVar` constructor of the [wiki:Commentary/Compiler/EntityTypes data type Var]. 
    8282
    83 Type variables range over both ''types'' (possibly of higher kind) or ''coercions''.  You could tell the difference between these two by taking the `typeKind` of the kind of the type variable, and seeing if you have sort `TY` or `CO`, but for efficiency the `TyVar` keeps a boolean flag, and returns a function:
     83== Overloaded types ==
     84
     85In Haskell we write
    8486{{{
    85   isCoercionVar :: TyVar -> Bool
     87f :: forall a. Num a => a -> a
    8688}}}
     89but in Core the `=>` is represented by an ordinary `FunTy`. So f's type looks like this:
     90{{{
     91   ForAllTy a (TyConApp num [TyVarTy a] `FunTy` TyVarTy a `FunTy` TyVarTy a)
     92where
     93   a   :: TyVar
     94   num :: TyCOn
     95}}}
     96Nevertheless, we can tell when a function argument is actually a predicate (and hence should be displayed with `=>`, etc), using
     97{{{
     98isPredTy :: Type -> Bool
     99}}}
     100The various forms of predicate can be extracted thus:
     101{{{
     102classifyPredType :: Type -> PredTree
     103
     104data PredTree = ClassPred Class [Type]   -- Class predicates e.g. (Num a)
     105              | EqPred Type Type         -- Equality predicates e.g. (a ~ b)
     106              | TuplePred [PredType]     -- Tuples of predicates e.g. (Num a, a~b)
     107              | IrredPred PredType       -- Higher order predicates e.g. (c a)
     108}}}
     109These functions are defined in module `Type`.
    87110 
    88111== Classifying types ==