Changeset 11167
- Timestamp:
- 16.12.2008 17:14:49 (15 months ago)
- Location:
- trunk/HasCASL
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/HasCASL/AsToLe.hs
r10463 r11167 14 14 module HasCASL.AsToLe where 15 15 16 import Common.AS_Annotation17 import Common.GlobalAnnotations18 import Common.Id19 import Common.Result20 import Common.ExtSign21 import Common.Prec22 import Common.Lib.State23 import qualified Data.Map as Map24 import qualified Data.Set as Set25 26 16 import HasCASL.As 27 import HasCASL.FoldType28 17 import HasCASL.Le 29 18 import HasCASL.TypeAna … … 37 26 import HasCASL.Merge 38 27 import HasCASL.MapTerm 39 import HasCASL.FoldTerm 28 29 import Common.AS_Annotation 30 import Common.GlobalAnnotations 31 import Common.Id 32 import Common.Result 33 import Common.ExtSign 34 import Common.Prec 35 import Common.Lib.State 36 37 import qualified Data.Map as Map 38 import qualified Data.Set as Set 40 39 import Data.Maybe 41 40 … … 199 198 return $ Internal ul ps 200 199 201 freeVars :: Term -> Set.Set VarDecl202 freeVars = foldTerm FoldRec203 { foldQualVar = \ _ t -> Set.singleton t204 , foldQualOp = \ _ _ _ _ _ _ _ -> Set.empty205 , foldApplTerm = \ _ t1 t2 _ -> Set.union t1 t2206 , foldTupleTerm = \ _ tts _ -> Set.unions tts207 , foldTypedTerm = \ _ ts _ _ _ -> ts208 , foldAsPattern = \ _ t ts _ -> Set.insert t ts209 , foldQuantifiedTerm = \ _ _ gvs ts _ -> Set.difference ts $210 foldr ( \ gv -> case gv of211 GenVarDecl t -> Set.insert t212 _ -> id) Set.empty gvs213 , foldLambdaTerm = \ _ pats _ ts _ -> Set.difference ts $ Set.unions pats214 , foldCaseTerm = \ _ ts tts _ -> Set.difference215 (Set.unions $ ts : map snd tts) $ Set.unions $ map fst tts216 , foldLetTerm = \ _ _ tts ts _ -> Set.difference217 (Set.unions $ ts : map snd tts) $ Set.unions $ map fst tts218 , foldResolvedMixTerm = \ _ _ _ tts _ -> Set.unions tts219 , foldTermToken = \ _ _ -> Set.empty220 , foldMixTypeTerm = \ _ _ _ _ -> Set.empty221 , foldMixfixTerm = \ _ tts -> Set.unions tts222 , foldBracketTerm = \ _ _ tts _ -> Set.unions tts223 , foldProgEq = \ _ ps ts _ -> (ps, ts) }224 225 -- | quantify226 mkEnvForall :: Env -> Term -> Range -> Term227 mkEnvForall e t ps =228 let tys = Set.fromList $ map (fst . snd) $ concatMap (leaves (>= 0))229 $ getAllTypes t230 tyVs = map ( \ (i, TypeVarDefn v vk rk c) -> GenTypeVarDecl $231 TypeArg i v vk rk c Other ps) $ Map.toList232 $ Map.filterWithKey ( \ i _ -> Set.member i tys) $ localTypeVars e233 vs = tyVs ++ map GenVarDecl (Set.toList $ freeVars t)234 in if null vs then t else QuantifiedTerm Universal vs t ps235 236 200 -- | analyse sig items 237 201 anaSigItems :: GenKind -> SigItems -> State Env SigItems -
trunk/HasCASL/OpDecl.hs
r10299 r11167 15 15 ( anaOpItem 16 16 , anaProgEq 17 , mkEnvForall 17 18 ) where 18 19 … … 33 34 34 35 import HasCASL.As 36 import HasCASL.FoldTerm 37 import HasCASL.FoldType 35 38 import HasCASL.HToken 36 39 import HasCASL.TypeAna … … 124 127 monoty = monoType ty 125 128 mt <- typeCheck Nothing $ TypedTerm rTrm AsType monoty ps 129 e <- get 126 130 newSc <- generalizeS $ TypeScheme newArgs 127 131 (getFunType ty partial … … 138 142 lhs = mkApplTerm ot pats 139 143 ef = mkEqTerm eqId monoty ps lhs lastTrm 140 f = mkForall 141 (map GenTypeVarDecl newArgs ++ 142 (map GenVarDecl $ concatMap extractVars pats)) ef 144 f = mkEnvForall e ef ps 143 145 addOpId i newSc Set.empty $ Definition br lamTrm 144 146 appendSentences … … 155 157 putLocalTypeVars tvs 156 158 return $ replaceAnnoted Nothing oi 159 160 freeVars :: Term -> Set.Set VarDecl 161 freeVars = foldTerm FoldRec 162 { foldQualVar = \ _ t -> Set.singleton t 163 , foldQualOp = \ _ _ _ _ _ _ _ -> Set.empty 164 , foldApplTerm = \ _ t1 t2 _ -> Set.union t1 t2 165 , foldTupleTerm = \ _ tts _ -> Set.unions tts 166 , foldTypedTerm = \ _ ts _ _ _ -> ts 167 , foldAsPattern = \ _ t ts _ -> Set.insert t ts 168 , foldQuantifiedTerm = \ _ _ gvs ts _ -> Set.difference ts $ 169 foldr ( \ gv -> case gv of 170 GenVarDecl t -> Set.insert t 171 _ -> id) Set.empty gvs 172 , foldLambdaTerm = \ _ pats _ ts _ -> Set.difference ts $ Set.unions pats 173 , foldCaseTerm = \ _ ts tts _ -> Set.difference 174 (Set.unions $ ts : map snd tts) $ Set.unions $ map fst tts 175 , foldLetTerm = \ _ _ tts ts _ -> Set.difference 176 (Set.unions $ ts : map snd tts) $ Set.unions $ map fst tts 177 , foldResolvedMixTerm = \ _ _ _ tts _ -> Set.unions tts 178 , foldTermToken = \ _ _ -> Set.empty 179 , foldMixTypeTerm = \ _ _ _ _ -> Set.empty 180 , foldMixfixTerm = \ _ tts -> Set.unions tts 181 , foldBracketTerm = \ _ _ tts _ -> Set.unions tts 182 , foldProgEq = \ _ ps ts _ -> (ps, ts) } 183 184 -- | quantify 185 mkEnvForall :: Env -> Term -> Range -> Term 186 mkEnvForall e t ps = 187 let tys = Set.fromList $ map (fst . snd) $ concatMap (leaves (>= 0)) 188 $ getAllTypes t 189 tyVs = map ( \ (i, TypeVarDefn v vk rk c) -> GenTypeVarDecl $ 190 TypeArg i v vk rk c Other ps) $ Map.toList 191 $ Map.filterWithKey ( \ i _ -> Set.member i tys) $ localTypeVars e 192 vs = tyVs ++ map GenVarDecl (Set.toList $ freeVars t) 193 in if null vs then t else QuantifiedTerm Universal vs t ps 157 194 158 195 -- | analyse a program equation