diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2012-04-13 21:40:56 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2012-04-13 21:40:56 +0100 |
commit | c5554f8290f5acc5f52ab1ea6488a75d0ffa34e5 (patch) | |
tree | 6552a19a76bdd58f09077196a037d192efe04916 /compiler/parser | |
parent | 3f46b1e3cb1dcf4e3ebb090284e0ca1d94f1eb17 (diff) | |
download | haskell-c5554f8290f5acc5f52ab1ea6488a75d0ffa34e5.tar.gz |
Allow kind-variable binders in type signatures
This is the last major addition to the kind-polymorphism story,
by allowing (Trac #5938)
type family F a -- F :: forall k. k -> *
data T a -- T :: forall k. k -> *
type instance F (T (a :: Maybe k)) = Char
The new thing is the explicit 'k' in the type signature on 'a',
which itself is inside a type pattern for F.
Main changes are:
* HsTypes.HsBSig now has a *pair* (kvs, tvs) of binders,
the kind variables and the type variables
* extractHsTyRdrTyVars returns a pair (kvs, tvs)
and the function itself has moved from RdrHsSyn to RnTypes
* Quite a bit of fiddling with
TcHsType.tcHsPatSigType and tcPatSig
which have become a bit simpler. I'm still not satisfied
though. There's some consequential fiddling in TcRules too.
* Removed the unused HsUtils.collectSigTysFromPats
There's a consequential wibble to Haddock too
Diffstat (limited to 'compiler/parser')
-rw-r--r-- | compiler/parser/Parser.y.pp | 6 | ||||
-rw-r--r-- | compiler/parser/ParserCore.y | 2 | ||||
-rw-r--r-- | compiler/parser/RdrHsSyn.lhs | 64 |
3 files changed, 4 insertions, 68 deletions
diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp index 9774c245e7..5fd0e9de76 100644 --- a/compiler/parser/Parser.y.pp +++ b/compiler/parser/Parser.y.pp @@ -729,7 +729,7 @@ data_or_newtype :: { Located NewOrData } opt_kind_sig :: { Located (Maybe (HsBndrSig (LHsKind RdrName))) } : { noLoc Nothing } - | '::' kind { LL (Just (HsBSig $2 placeHolderBndrs)) } + | '::' kind { LL (Just (mkHsBSig $2)) } -- tycl_hdr parses the header of a class or data type decl, -- which takes the form @@ -876,7 +876,7 @@ rule_var_list :: { [RuleBndr RdrName] } rule_var :: { RuleBndr RdrName } : varid { RuleBndr $1 } - | '(' varid '::' ctype ')' { RuleBndrSig $2 (HsBSig $4 placeHolderBndrs) } + | '(' varid '::' ctype ')' { RuleBndrSig $2 (mkHsBSig $4) } ----------------------------------------------------------------------------- -- Warnings and deprecations (c.f. rules) @@ -1109,7 +1109,7 @@ tv_bndrs :: { [LHsTyVarBndr RdrName] } tv_bndr :: { LHsTyVarBndr RdrName } : tyvar { L1 (UserTyVar (unLoc $1)) } - | '(' tyvar '::' kind ')' { LL (KindedTyVar (unLoc $2) (HsBSig $4 placeHolderBndrs)) } + | '(' tyvar '::' kind ')' { LL (KindedTyVar (unLoc $2) (mkHsBSig $4)) } fds :: { Located [Located (FunDep RdrName)] } : {- empty -} { noLoc [] } diff --git a/compiler/parser/ParserCore.y b/compiler/parser/ParserCore.y index 70a0e886f1..eee8831065 100644 --- a/compiler/parser/ParserCore.y +++ b/compiler/parser/ParserCore.y @@ -377,7 +377,7 @@ ifaceArrow ifT1 ifT2 = IfaceFunTy ifT1 ifT2 toHsTvBndr :: IfaceTvBndr -> LHsTyVarBndr RdrName toHsTvBndr (tv,k) = noLoc $ KindedTyVar (mkRdrUnqual (mkTyVarOccFS tv)) bsig where - bsig = HsBSig (toHsKind k) placeHolderBndrs + bsig = mkHsBSig (toHsKind k) ifaceExtRdrName :: Name -> RdrName ifaceExtRdrName name = mkOrig (nameModule name) (nameOccName name) diff --git a/compiler/parser/RdrHsSyn.lhs b/compiler/parser/RdrHsSyn.lhs index 91bab6c3fb..099acd7388 100644 --- a/compiler/parser/RdrHsSyn.lhs +++ b/compiler/parser/RdrHsSyn.lhs @@ -5,8 +5,6 @@ Functions over HsSyn specialised to RdrName. \begin{code} module RdrHsSyn ( - extractHsTyRdrTyVars, extractHsTysRdrTyVars, - mkHsOpApp, mkHsIntegral, mkHsFractional, mkHsIsString, mkHsDo, mkHsSplice, mkTopSpliceDecl, @@ -78,11 +76,9 @@ import Bag ( Bag, emptyBag, consBag ) import Outputable import FastString import Maybes -import Util ( filterOut ) import Control.Applicative ((<$>)) import Control.Monad import Text.ParserCombinators.ReadP as ReadP -import Data.List ( nub ) import Data.Char #include "HsVersions.h" @@ -91,66 +87,6 @@ import Data.Char %************************************************************************ %* * -\subsection{A few functions over HsSyn at RdrName} -%* * -%************************************************************************ - -extractHsTyRdrNames finds the free variables of a HsType -It's used when making the for-alls explicit. - -\begin{code} -extractHsTyRdrTyVars :: LHsType RdrName -> [RdrName] -extractHsTyRdrTyVars ty = nub (extract_lty ty []) - -extractHsTysRdrTyVars :: [LHsType RdrName] -> [RdrName] -extractHsTysRdrTyVars ty = nub (extract_ltys ty []) - -extract_lctxt :: LHsContext RdrName -> [RdrName] -> [RdrName] -extract_lctxt ctxt acc = foldr extract_lty acc (unLoc ctxt) - -extract_ltys :: [LHsType RdrName] -> [RdrName] -> [RdrName] -extract_ltys tys acc = foldr extract_lty acc tys - --- IA0_NOTE: Should this function also return kind variables? --- (explicit kind poly) -extract_lty :: LHsType RdrName -> [RdrName] -> [RdrName] -extract_lty (L _ ty) acc - = case ty of - HsTyVar tv -> extract_tv tv acc - HsBangTy _ ty -> extract_lty ty acc - HsRecTy flds -> foldr (extract_lty . cd_fld_type) acc flds - HsAppTy ty1 ty2 -> extract_lty ty1 (extract_lty ty2 acc) - HsListTy ty -> extract_lty ty acc - HsPArrTy ty -> extract_lty ty acc - HsTupleTy _ tys -> extract_ltys tys acc - HsFunTy ty1 ty2 -> extract_lty ty1 (extract_lty ty2 acc) - HsIParamTy _ ty -> extract_lty ty acc - HsEqTy ty1 ty2 -> extract_lty ty1 (extract_lty ty2 acc) - HsOpTy ty1 (_, (L _ tv)) ty2 -> extract_tv tv (extract_lty ty1 (extract_lty ty2 acc)) - HsParTy ty -> extract_lty ty acc - HsCoreTy {} -> acc -- The type is closed - HsQuasiQuoteTy {} -> acc -- Quasi quotes mention no type variables - HsSpliceTy {} -> acc -- Type splices mention no type variables - HsKindSig ty _ -> extract_lty ty acc - HsForAllTy _ [] cx ty -> extract_lctxt cx (extract_lty ty acc) - HsForAllTy _ tvs cx ty -> acc ++ (filterOut (`elem` locals) $ - extract_lctxt cx (extract_lty ty [])) - where - locals = hsLTyVarNames tvs - HsDocTy ty _ -> extract_lty ty acc - HsExplicitListTy _ tys -> extract_ltys tys acc - HsExplicitTupleTy _ tys -> extract_ltys tys acc - HsTyLit _ -> acc - HsWrapTy _ _ -> panic "extract_lty" - -extract_tv :: RdrName -> [RdrName] -> [RdrName] -extract_tv tv acc | isRdrTyVar tv = tv : acc - | otherwise = acc -\end{code} - - -%************************************************************************ -%* * \subsection{Construction functions for Rdr stuff} %* * %************************************************************************ |