[split type environment into concrete and mutable sets, to avoid retraversing the concrete imported types
John Meacham <john@repetae.net>**20100806090349
 Ignore-this: c276618b4b968d9149e6b3dfc36d162a
] hunk ./src/FrontEnd/Tc/Monad.hs 101
-    tcCurrentEnv        :: Map.Map Name Sigma,
+    tcConcreteEnv       :: Map.Map Name Sigma,
+    tcMutableEnv        :: Map.Map Name Sigma,
hunk ./src/FrontEnd/Tc/Monad.hs 111
-    collectedPreds   :: Preds,
-    existentialPreds :: Preds,
-    constraints      :: Seq.Seq Constraint,
-    checkedRules     :: Seq.Seq Rule,
+    collectedPreds   :: !Preds,
+    existentialPreds :: !Preds,
+    constraints      :: !(Seq.Seq Constraint),
+    checkedRules     :: !(Seq.Seq Rule),
hunk ./src/FrontEnd/Tc/Monad.hs 116
-    tcWarnings       :: Seq.Seq Warning,
+    tcWarnings       :: !(Seq.Seq Warning),
hunk ./src/FrontEnd/Tc/Monad.hs 141
-     else local (tcCurrentEnv_u (Map.fromList te' `Map.union`)) act
+     else local (tcMutableEnv_u (Map.fromList te' `Map.union`)) act
hunk ./src/FrontEnd/Tc/Monad.hs 181
-        tcCurrentEnv = tcInfoEnv tcInfo `mappend` tcInfoSigEnv tcInfo,
+        tcConcreteEnv = tcInfoEnv tcInfo `mappend` tcInfoSigEnv tcInfo,
+        tcMutableEnv = mempty,
hunk ./src/FrontEnd/Tc/Monad.hs 226
+askCurrentEnv = do
+    env1 <- asks tcConcreteEnv
+    env2 <- asks tcMutableEnv
+    return (env2 `Map.union` env1)
hunk ./src/FrontEnd/Tc/Monad.hs 233
-    env <- asks tcCurrentEnv
+    env <- askCurrentEnv
hunk ./src/FrontEnd/Tc/Monad.hs 260
-    env <- asks tcCurrentEnv
+    env <- askCurrentEnv
hunk ./src/FrontEnd/Tc/Monad.hs 398
-    env <- asks tcCurrentEnv
+    env <- asks tcMutableEnv
hunk ./src/FrontEnd/Tc/Type.hs 145
-data UnVarOpt = UnVarOpt {
-    openBoxes :: {-# UNPACK #-} !Bool,
-    failEmptyMetaVar :: {-# UNPACK #-} !Bool
+newtype UnVarOpt = UnVarOpt {
+    failEmptyMetaVar :: Bool
hunk ./src/FrontEnd/Tc/Type.hs 151
-flattenType t =  unVar UnVarOpt { openBoxes = True, failEmptyMetaVar = False } t
+flattenType t =  unVar UnVarOpt { failEmptyMetaVar = False } t
hunk ./src/FrontEnd/Tc/Type.hs 230
--}
hunk ./src/FrontEnd/Tc/Type.hs 243
+-}
+
+freeMetaVars :: Type -> S.Set MetaVar
+freeMetaVars t = f t where
+    f (TMetaVar mv) = S.singleton mv
+    f (TAp l r) = f l `S.union` f r
+    f (TArrow l r) = f l `S.union` f r
+    f (TAssoc c cas eas) = S.unions (map f cas ++ map f eas)
+    f (TForAll ta (ps :=> t)) = S.unions (f t:map f2 ps)
+    f (TExists ta (ps :=> t)) = S.unions (f t:map f2 ps)
+    f _ = S.empty
+    f2 (IsIn c t) = f t
+    f2 (IsEq t1 t2) = f t1 `S.union` f t2