Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : ghc-kinds

http://hackage.haskell.org/trac/ghc/changeset/1876794f60707806bda9eeadb780a66564fba6ca

>---------------------------------------------------------------

commit 1876794f60707806bda9eeadb780a66564fba6ca
Author: Julien Cretin <g...@ia0.eu>
Date:   Wed Sep 14 11:52:28 2011 +0200

    tyVarsOfType returns all variables, even in kinds

>---------------------------------------------------------------

 compiler/types/TypeRep.lhs |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/compiler/types/TypeRep.lhs b/compiler/types/TypeRep.lhs
index 7007bb8..e6b8edd 100644
--- a/compiler/types/TypeRep.lhs
+++ b/compiler/types/TypeRep.lhs
@@ -28,6 +28,7 @@ module TypeRep (
 
         -- Free variables
         tyVarsOfType, tyVarsOfTypes,
+        tyVarsOfTypeStratified, tyVarsOfTypesStratified,
 
         -- Substitutions
         TvSubst(..), TvSubstEnv
@@ -288,14 +289,32 @@ isLiftedTypeKind _                = False
 \begin{code}
 tyVarsOfType :: Type -> VarSet
 -- ^ NB: for type synonyms tyVarsOfType does /not/ expand the synonym
-tyVarsOfType (TyVarTy v)         = unitVarSet v
+-- tyVarsOfType returns variables at any level (types or kinds)
+-- see tyVarsOfTypeStratified for a function that returns only current level 
variables
+tyVarsOfType (TyVarTy v)         = unitVarSet v `unionVarSet` tyVarsOfType 
(tyVarKind v)
 tyVarsOfType (TyConApp _ tys)    = tyVarsOfTypes tys
 tyVarsOfType (FunTy arg res)     = tyVarsOfType arg `unionVarSet` tyVarsOfType 
res
 tyVarsOfType (AppTy fun arg)     = tyVarsOfType fun `unionVarSet` tyVarsOfType 
arg
-tyVarsOfType (ForAllTy tyvar ty) = delVarSet (tyVarsOfType ty) tyvar
+tyVarsOfType (ForAllTy tyvar ty) = delVarSet (tyVarsOfType ty) tyvar 
`unionVarSet` tyVarsOfType (tyVarKind tyvar)
 
 tyVarsOfTypes :: [Type] -> TyVarSet
 tyVarsOfTypes tys = foldr (unionVarSet . tyVarsOfType) emptyVarSet tys
+
+tyVarsOfTypeStratified :: Type -> VarSet
+-- only returns variables of the current level (don't look in kind signatures)
+tyVarsOfTypeStratified (TyVarTy v)
+  = unitVarSet v
+tyVarsOfTypeStratified (TyConApp _ tys)
+  = tyVarsOfTypesStratified tys
+tyVarsOfTypeStratified (FunTy arg res)
+  = tyVarsOfTypeStratified arg `unionVarSet` tyVarsOfTypeStratified res
+tyVarsOfTypeStratified (AppTy fun arg)
+  = tyVarsOfTypeStratified fun `unionVarSet` tyVarsOfTypeStratified arg
+tyVarsOfTypeStratified (ForAllTy tyvar ty)
+  = delVarSet (tyVarsOfTypeStratified ty) tyvar
+
+tyVarsOfTypesStratified :: [Type] -> VarSet
+tyVarsOfTypesStratified tys = foldr (unionVarSet . tyVarsOfTypeStratified) 
emptyVarSet tys
 \end{code}
 
 %************************************************************************



_______________________________________________
Cvs-ghc mailing list
Cvs-ghc@haskell.org
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to