diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2018-12-17 20:54:36 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-03-01 16:26:02 -0500 |
commit | c26d299dc422f43b8c37da4b26da2067eedcbae8 (patch) | |
tree | 517d7b87043152bee667485e186314d19b55cfba /compiler/deSugar | |
parent | f838809f1e73c20bc70926fe98e735297572ac60 (diff) | |
download | haskell-c26d299dc422f43b8c37da4b26da2067eedcbae8.tar.gz |
Visible dependent quantification
This implements GHC proposal 35
(https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0035-forall-arrow.rst)
by adding the ability to write kinds with
visible dependent quantification (VDQ).
Most of the work for supporting VDQ was actually done _before_ this
patch. That is, GHC has been able to reason about kinds with VDQ for
some time, but it lacked the ability to let programmers directly
write these kinds in the source syntax. This patch is primarly about
exposing this ability, by:
* Changing `HsForAllTy` to add an additional field of type
`ForallVisFlag` to distinguish between invisible `forall`s (i.e,
with dots) and visible `forall`s (i.e., with arrows)
* Changing `Parser.y` accordingly
The rest of the patch mostly concerns adding validity checking to
ensure that VDQ is never used in the type of a term (as permitting
this would require full-spectrum dependent types). This is
accomplished by:
* Adding a `vdqAllowed` predicate to `TcValidity`.
* Introducing `splitLHsSigmaTyInvis`, a variant of `splitLHsSigmaTy`
that only splits invisible `forall`s. This function is used in
certain places (e.g., in instance declarations) to ensure that GHC
doesn't try to split visible `forall`s (e.g., if it tried splitting
`instance forall a -> Show (Blah a)`, then GHC would mistakenly
allow that declaration!)
This also updates Template Haskell by introducing a new `ForallVisT`
constructor to `Type`.
Fixes #16326. Also fixes #15658 by documenting this feature in the
users' guide.
Diffstat (limited to 'compiler/deSugar')
-rw-r--r-- | compiler/deSugar/DsMeta.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/compiler/deSugar/DsMeta.hs b/compiler/deSugar/DsMeta.hs index a8a4fb6b40..5e0976d1a2 100644 --- a/compiler/deSugar/DsMeta.hs +++ b/compiler/deSugar/DsMeta.hs @@ -1144,18 +1144,21 @@ repLTys tys = mapM repLTy tys repLTy :: LHsType GhcRn -> DsM (Core TH.TypeQ) repLTy ty = repTy (unLoc ty) -repForall :: HsType GhcRn -> DsM (Core TH.TypeQ) +repForall :: ForallVisFlag -> HsType GhcRn -> DsM (Core TH.TypeQ) -- Arg of repForall is always HsForAllTy or HsQualTy -repForall ty +repForall fvf ty | (tvs, ctxt, tau) <- splitLHsSigmaTy (noLoc ty) = addHsTyVarBinds tvs $ \bndrs -> do { ctxt1 <- repLContext ctxt ; ty1 <- repLTy tau - ; repTForall bndrs ctxt1 ty1 } + ; case fvf of + ForallVis -> repTForallVis bndrs ty1 -- forall a -> {...} + ForallInvis -> repTForall bndrs ctxt1 ty1 -- forall a. C a => {...} + } repTy :: HsType GhcRn -> DsM (Core TH.TypeQ) -repTy ty@(HsForAllTy {}) = repForall ty -repTy ty@(HsQualTy {}) = repForall ty +repTy ty@(HsForAllTy {hst_fvf = fvf}) = repForall fvf ty +repTy ty@(HsQualTy {}) = repForall ForallInvis ty repTy (HsTyVar _ _ (dL->L _ n)) | isLiftedTypeKindTyConName n = repTStar @@ -2467,6 +2470,10 @@ repTForall :: Core [TH.TyVarBndrQ] -> Core TH.CxtQ -> Core TH.TypeQ repTForall (MkC tvars) (MkC ctxt) (MkC ty) = rep2 forallTName [tvars, ctxt, ty] +repTForallVis :: Core [TH.TyVarBndrQ] -> Core TH.TypeQ + -> DsM (Core TH.TypeQ) +repTForallVis (MkC tvars) (MkC ty) = rep2 forallVisTName [tvars, ty] + repTvar :: Core TH.Name -> DsM (Core TH.TypeQ) repTvar (MkC s) = rep2 varTName [s] |