Commit 67465497 authored by's avatar

Add kind equalities to GHC.

This implements the ideas originally put forward in
"System FC with Explicit Kind Equality" (ICFP'13).

There are several noteworthy changes with this patch:
 * We now have casts in types. These change the kind
   of a type. See new constructor `CastTy`.

 * All types and all constructors can be promoted.
   This includes GADT constructors. GADT pattern matches
   take place in type family equations. In Core,
   types can now be applied to coercions via the
   `CoercionTy` constructor.

 * Coercions can now be heterogeneous, relating types
   of different kinds. A coercion proving `t1 :: k1 ~ t2 :: k2`
   proves both that `t1` and `t2` are the same and also that
   `k1` and `k2` are the same.

 * The `Coercion` type has been significantly enhanced.
   The documentation in `docs/core-spec/core-spec.pdf` reflects
   the new reality.

 * The type of `*` is now `*`. No more `BOX`.

 * Users can write explicit kind variables in their code,
   anywhere they can write type variables. For backward compatibility,
   automatic inference of kind-variable binding is still permitted.

 * The new extension `TypeInType` turns on the new user-facing

 * Type families and synonyms are now promoted to kinds. This causes
   trouble with parsing `*`, leading to the somewhat awkward new
   `HsAppsTy` constructor for `HsType`. This is dispatched with in
   the renamer, where the kind `*` can be told apart from a
   type-level multiplication operator. Without `-XTypeInType` the
   old behavior persists. With `-XTypeInType`, you need to import
   `Data.Kind` to get `*`, also known as `Type`.

 * The kind-checking algorithms in TcHsType have been significantly
   rewritten to allow for enhanced kinds.

 * The new features are still quite experimental and may be in flux.

 * TODO: Several open tickets: #11195, #11196, #11197, #11198, #11203.

 * TODO: Update user manual.

Tickets addressed: #9017, #9173, #7961, #10524, #8566, #11142.
Updates Haddock submodule.
parent 6e56ac58
[submodule "libraries/binary"]
path = libraries/binary
url = ../packages/binary.git
url =
ignore = untracked
[submodule "libraries/bytestring"]
path = libraries/bytestring
url = ../packages/bytestring.git
url =
ignore = untracked
[submodule "libraries/Cabal"]
path = libraries/Cabal
url = ../packages/Cabal.git
url =
ignore = untracked
[submodule "libraries/containers"]
path = libraries/containers
url = ../packages/containers.git
url =
ignore = untracked
[submodule "libraries/haskeline"]
path = libraries/haskeline
url = ../packages/haskeline.git
url =
ignore = untracked
[submodule "libraries/pretty"]
path = libraries/pretty
url = ../packages/pretty.git
url =
ignore = untracked
[submodule "libraries/terminfo"]
path = libraries/terminfo
url = ../packages/terminfo.git
url =
ignore = untracked
[submodule "libraries/transformers"]
path = libraries/transformers
url = ../packages/transformers.git
url =
ignore = untracked
[submodule "libraries/xhtml"]
path = libraries/xhtml
url = ../packages/xhtml.git
url =
ignore = untracked
[submodule "libraries/Win32"]
path = libraries/Win32
url = ../packages/Win32.git
url =
ignore = untracked
[submodule "libraries/primitive"]
path = libraries/primitive
url = ../packages/primitive.git
url =
ignore = untracked
[submodule "libraries/vector"]
path = libraries/vector
url = ../packages/vector.git
url =
ignore = untracked
[submodule "libraries/time"]
path = libraries/time
url = ../packages/time.git
url =
ignore = untracked
[submodule "libraries/random"]
path = libraries/random
url = ../packages/random.git
url =
ignore = untracked
[submodule "libraries/array"]
path = libraries/array
url = ../packages/array.git
url =
ignore = none
[submodule "libraries/deepseq"]
path = libraries/deepseq
url = ../packages/deepseq.git
url =
ignore = none
[submodule "libraries/directory"]
path = libraries/directory
url = ../packages/directory.git
url =
ignore = none
[submodule "libraries/filepath"]
path = libraries/filepath
url = ../packages/filepath.git
url =
ignore = none
[submodule "libraries/hoopl"]
path = libraries/hoopl
url = ../packages/hoopl.git
url =
ignore = none
[submodule "libraries/hpc"]
path = libraries/hpc
url = ../packages/hpc.git
url =
ignore = none
[submodule "libraries/process"]
path = libraries/process
url = ../packages/process.git
url =
ignore = none
[submodule "libraries/unix"]
path = libraries/unix
url = ../packages/unix.git
url =
ignore = none
[submodule "libraries/parallel"]
path = libraries/parallel
url = ../packages/parallel.git
url =
ignore = none
[submodule "libraries/stm"]
path = libraries/stm
url = ../packages/stm.git
url =
ignore = none
[submodule "libraries/dph"]
path = libraries/dph
url = ../packages/dph.git
url =
ignore = none
[submodule "utils/haddock"]
path = utils/haddock
url = ../haddock.git
url =
ignore = none
branch = ghc-head
[submodule "nofib"]
path = nofib
url = ../nofib.git
url =
ignore = none
[submodule "utils/hsc2hs"]
path = utils/hsc2hs
url = ../hsc2hs.git
url =
ignore = none
[submodule "libffi-tarballs"]
path = libffi-tarballs
url = ../libffi-tarballs.git
url =
ignore = none
[submodule ".arc-linters/arcanist-external-json-linter"]
path = .arc-linters/arcanist-external-json-linter
The Glasgow Haskell Compiler
Dependent Types Branch of GHC
[![Build Status](](
This is a fork of GHC, with work toward supporting dependent types.
Anyone is welcome to download and play with this implementation,
and I am happy to receive feedback and issue reports on GitHub.
This is the source tree for [GHC][1], a compiler and interactive
environment for the Haskell functional programming language.
There are two options of using this branch: manual, and Nix-based.
For more information, visit [GHC's web site][1].
This code should build, but I have tested it only on `DEBUG` settings;
I recommend using build style `devel2` in ``.
Here is a minimal script you can follow to build this at home;
see the [GHC Building Guide] [3] for more info.
git clone
cd ghc
git checkout nokinds
git remote set-url origin git:// # so submodules work
git submodule update --init
cd mk
## edit to uncomment the line to choose the `devel2` configuration
cd ..
perl boot
Check out the `testsuite/tests/dependent/should_compile` directory for
a few sample programs that should compile on this fork of GHC.
For more information about GHC, visit [GHC's web site][1].
Information for developers of GHC can be found on the [GHC Trac][2].
Thanks to @deepfire, this branch is available in Nixpkgs, which means that with
some effort it can be fairly automatically employed to build any package from
Hackage. This way, though, requires that one installs the Nix package manager in
parallel with the system package manager -- and this option is currently
unavailable on Windows.
Here are the instructions:
1. To install the Nix package manager, taking over /nix for package storage:
curl | sh
2. Make Nix use the `master` repository of Nixpkgs package definitions:
Getting the Source
git clone
pushd ~/.nix-defexpr
rm -rf channels
ln -s ../nixpkgs
echo 'export NIX_PATH=nixpkgs=/home/---<USERNAME>---/nixpkgs' >> ~/.bashrc
export NIX_PATH=nixpkgs=/home/---<USERNAME>---/nixpkgs
There are two ways to get a source tree:
3. [OPTIONAL] To enable prebuilt binaries from Peter Simons/NixOS Hydra servers:
1. *Download source tarballs*
sudo mkdir /etc/nix
echo 'binary-caches =' | sudo dd of=/etc/nix/nix.conf
Download the GHC source distribution:
# If you don't do that, everything will still work, just it'll have
# to build everything from source.
4. Enter a shell with `ghc-nokinds` available:
which contains GHC itself and the "boot" libraries.
nix-shell -p haskell.compiler.ghcNokinds
2. *Check out the source code from git*
5. See it's indeed `nokinds`:
$ git clone --recursive git://
runhaskell KindEqualities2.hs
Note: cloning GHC from Github requires a special setup. See [Getting a GHC
repository from Github] [7].
To apply 'nokinds' to building packages from Hackage, the best option would be
to follow instructions from the "Nix loves Haskell" talk by Peter Simons:
**DO NOT submit pull request directly to the github repo.**
*See the GHC team's working conventions re [how to contribute a patch to GHC]( "").*
..where the relevant compiler name would be "ghcNokinds".
Building & Installing
......@@ -413,6 +413,10 @@ isBoxed :: Boxity -> Bool
isBoxed Boxed = True
isBoxed Unboxed = False
instance Outputable Boxity where
ppr Boxed = text "Boxed"
ppr Unboxed = text "Unboxed"
* *
......@@ -32,7 +32,7 @@ import Unique
import Util
import Name
import BasicTypes
import TypeRep (Type, ThetaType)
import TyCoRep (Type, ThetaType)
import Var
import Type (mkTyConApp)
......@@ -169,7 +169,7 @@ conLikeResTy (PatSynCon ps) tys = patSynInstResTy ps tys
-- 7) The original result type
conLikeFullSig :: ConLike
-> ([TyVar], [TyVar], [(TyVar,Type)]
-> ([TyVar], [TyVar], [EqSpec]
, ThetaType, ThetaType, [Type], Type)
conLikeFullSig (RealDataCon con) =
let (univ_tvs, ex_tvs, eq_spec, theta, arg_tys, res_ty) = dataConFullSig con
This diff is collapsed.
......@@ -6,10 +6,13 @@ import FieldLabel ( FieldLabel )
import Unique ( Uniquable )
import Outputable ( Outputable, OutputableBndr )
import BasicTypes (Arity)
import {-# SOURCE #-} TypeRep (Type, ThetaType)
import {-# SOURCE #-} TyCoRep (Type, ThetaType)
data DataCon
data DataConRep
data EqSpec
eqSpecTyVar :: EqSpec -> TyVar
dataConName :: DataCon -> Name
dataConTyCon :: DataCon -> TyCon
dataConExTyVars :: DataCon -> [TyVar]
......@@ -18,7 +21,7 @@ dataConFieldLabels :: DataCon -> [FieldLabel]
dataConInstOrigArgTys :: DataCon -> [Type] -> [Type]
dataConStupidTheta :: DataCon -> ThetaType
dataConFullSig :: DataCon
-> ([TyVar], [TyVar], [(TyVar,Type)], ThetaType, [Type], Type)
-> ([TyVar], [TyVar], [EqSpec], ThetaType, [Type], Type)
instance Eq DataCon
instance Ord DataCon
......@@ -17,7 +17,7 @@
-- * 'Name.Name': see "Name#name_types"
-- * 'Id.Id' represents names that not only have a 'Name.Name' but also a 'TypeRep.Type' and some additional
-- * 'Id.Id' represents names that not only have a 'Name.Name' but also a 'TyCoRep.Type' and some additional
-- details (a 'IdInfo.IdInfo' and one of 'Var.LocalIdDetails' or 'IdInfo.GlobalIdDetails') that
-- are added, modified and inspected by various compiler passes. These 'Var.Var' names may either
-- be global or local, see "Var#globalvslocal"
......@@ -30,11 +30,14 @@ module Id (
-- ** Simple construction
mkGlobalId, mkVanillaGlobal, mkVanillaGlobalWithInfo,
mkLocalId, mkLocalIdWithInfo, mkExportedLocalId,
mkSysLocal, mkSysLocalM, mkUserLocal, mkUserLocalM,
mkLocalId, mkLocalCoVar, mkLocalIdOrCoVar,
mkLocalIdWithInfo, mkExportedLocalId,
mkSysLocal, mkSysLocalM, mkSysLocalOrCoVar, mkSysLocalOrCoVarM,
mkUserLocal, mkUserLocalCoVar, mkUserLocalOrCoVar,
mkTemplateLocals, mkTemplateLocalsNum, mkTemplateLocal,
mkWorkerId, mkWiredInIdName,
-- ** Taking an Id apart
idName, idType, idUnique, idInfo, idDetails, idRepArity,
......@@ -111,7 +114,7 @@ import IdInfo
import BasicTypes
-- Imported and re-exported
import Var( Id, DictId,
import Var( Id, CoVar, DictId,
idInfo, idDetails, globaliseId, varType,
isId, isLocalId, isGlobalId, isExportedId )
import qualified Var
......@@ -191,7 +194,7 @@ localiseId id
| ASSERT( isId id ) isLocalId id && isInternalName name
= id
| otherwise
= mkLocalIdWithInfo (localiseName name) (idType id) (idInfo id)
= Var.mkLocalVar (idDetails id) (localiseName name) (idType id) (idInfo id)
name = idName id
......@@ -249,7 +252,31 @@ mkVanillaGlobalWithInfo = mkGlobalId VanillaId
mkLocalId :: Name -> Type -> Id
mkLocalId name ty = mkLocalIdWithInfo name ty
(vanillaIdInfo `setOneShotInfo` typeOneShot ty)
-- It's tempting to ASSERT( not (isCoercionType ty) ), but don't. Sometimes,
-- the type is a panic. (Search invented_id)
-- | Make a local CoVar
mkLocalCoVar :: Name -> Type -> CoVar
mkLocalCoVar name ty
= ASSERT( isCoercionType ty )
Var.mkLocalVar CoVarId name ty (vanillaIdInfo `setOneShotInfo` typeOneShot ty)
-- | Like 'mkLocalId', but checks the type to see if it should make a covar
mkLocalIdOrCoVar :: Name -> Type -> Id
mkLocalIdOrCoVar name ty
| isCoercionType ty = mkLocalCoVar name ty
| otherwise = mkLocalId name ty