Add support for evaluation of type-level natural numbers.
This patch implements some simple evaluation of type-level expressions featuring natural numbers. We can evaluate *concrete* expressions that use the built-in type families (+), (*), (^), and (<=?), declared in GHC.TypeLits. We can also do some type inference involving these functions. For example, if we encounter a constraint such as `(2 + x) ~ 5` we can infer that `x` must be 3. Note, however, this is used only to resolve unification variables (i.e., as a form of a constraint improvement) and not to generate new facts. This is similar to how functional dependencies work in GHC. The patch adds a new form of coercion, `AxiomRuleCo`, which makes use of a new form of axiom called `CoAxiomRule`. This is the form of evidence generate when we solve a constraint, such as `(1 + 2) ~ 3`. The patch also adds support for built-in type-families, by adding a new form of TyCon rhs: `BuiltInSynFamTyCon`. such built-in type-family constructors contain a record with functions that are used by the constraint solver to simplify and improve constraints involving the built-in function (see `TcInteract`). The record in defined in `FamInst`. The type constructors and rules for evaluating the type-level functions are in a new module called `TcTypeNats`.
Showing
- compiler/coreSyn/CoreLint.lhs 48 additions, 0 deletionscompiler/coreSyn/CoreLint.lhs
- compiler/coreSyn/MkExternalCore.lhs 2 additions, 0 deletionscompiler/coreSyn/MkExternalCore.lhs
- compiler/coreSyn/TrieMap.lhs 34 additions, 5 deletionscompiler/coreSyn/TrieMap.lhs
- compiler/deSugar/DsBinds.lhs 5 additions, 0 deletionscompiler/deSugar/DsBinds.lhs
- compiler/ghc.cabal.in 1 addition, 0 deletionscompiler/ghc.cabal.in
- compiler/ghc.mk 2 additions, 1 deletioncompiler/ghc.mk
- compiler/iface/IfaceSyn.lhs 4 additions, 0 deletionscompiler/iface/IfaceSyn.lhs
- compiler/iface/IfaceType.lhs 19 additions, 1 deletioncompiler/iface/IfaceType.lhs
- compiler/iface/MkIface.lhs 3 additions, 0 deletionscompiler/iface/MkIface.lhs
- compiler/iface/TcIface.lhs 12 additions, 0 deletionscompiler/iface/TcIface.lhs
- compiler/main/PprTyThing.hs 3 additions, 0 deletionscompiler/main/PprTyThing.hs
- compiler/prelude/PrelInfo.lhs 3 additions, 1 deletioncompiler/prelude/PrelInfo.lhs
- compiler/prelude/PrelNames.lhs 5 additions, 13 deletionscompiler/prelude/PrelNames.lhs
- compiler/prelude/TysWiredIn.lhs 15 additions, 0 deletionscompiler/prelude/TysWiredIn.lhs
- compiler/typecheck/FamInst.lhs 27 additions, 1 deletioncompiler/typecheck/FamInst.lhs
- compiler/typecheck/FamInst.lhs-boot 5 additions, 0 deletionscompiler/typecheck/FamInst.lhs-boot
- compiler/typecheck/TcEvidence.lhs 32 additions, 0 deletionscompiler/typecheck/TcEvidence.lhs
- compiler/typecheck/TcHsSyn.lhs 4 additions, 0 deletionscompiler/typecheck/TcHsSyn.lhs
- compiler/typecheck/TcInteract.lhs 44 additions, 3 deletionscompiler/typecheck/TcInteract.lhs
- compiler/typecheck/TcRnDriver.lhs 1 addition, 0 deletionscompiler/typecheck/TcRnDriver.lhs
compiler/typecheck/FamInst.lhs-boot
0 → 100644
Please register or sign in to comment