PPolyTyConsHOL2IsaUtils.hs revision df2a122c5ecd7d995323c3f0754e1a2a4e3dc0a8
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzModule : $Header$
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzDescription : translating a HasCASL subset to Isabelle
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzCopyright : (c) C. Maeder, DFKI 2008
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzMaintainer : Christian.Maeder@dfki.de
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzStability : provisional
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzPortability : portable
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzutility function for translation from HasCASL to Isabelle leaving open how
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzpartial values are interpreted
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzmodule Comorphisms.PPolyTyConsHOL2IsaUtils where
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport HasCASL.Unify (substGen)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuimport qualified Data.Map as Map
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport qualified Data.Set as Set
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savuimport Data.List (elemIndex)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savuimport Data.Maybe (catMaybes, isNothing)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavumapTheory :: Simplifier -> (Env, [Named Le.Sentence])
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavumapTheory simpF (env, sens) = do
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu let tyToks = typeToks env
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu sign <- transSignature env tyToks
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu isens <- mapM (mapNamedM $ transSentence env tyToks simpF) sens
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu (dt, _, _) <- foldM (transDataEntries env tyToks)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu ([], Set.empty, Set.empty) $ filter (not . null) $ map
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu (\ ns -> case sentence ns of
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu DatatypeSen ds -> ds
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu _ -> []) sens
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu return ( sign { domainTab = reverse dt }
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu , filter (\ ns -> sentence ns /= mkSen true) isens)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu-- * Signature
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavubaseSign :: BaseSig
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavubaseSign = MainHC_thy
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavutransAssumps :: GlobalAnnos -> Set.Set String -> Assumps -> Result ConstTab
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavutransAssumps ga toks = foldM insertOps Map.empty . Map.toList where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu insertOps m (name, ops) =
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu let chk = isPlainFunType
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu in case map opType $ Set.toList ops of
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu [TypeScheme _ op _ ] -> do
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu ty <- funType op
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu (mkIsaConstT (isPredType op) ga (chk ty)
3051a3502f027f3d7bb750a1d7a6b1b43cdd2a86Robert Savu name baseSign toks) (transPlainFunType ty) m
3051a3502f027f3d7bb750a1d7a6b1b43cdd2a86Robert Savu infos -> foldM ( \ m' (i, TypeScheme _ op _) -> do
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu ty <- funType op
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu (mkIsaConstIT (isPredType op) ga (chk ty)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu name i baseSign toks) (transPlainFunType ty) m'
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu ) m $ zip [1..] infos
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- all possible tokens of mixfix identifiers that must not be used as variables
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavugetAssumpsToks :: Assumps -> Set.Set String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavugetAssumpsToks = Map.foldWithKey (\ i ops s ->
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu $ zipWith (\ o _ -> getConstIsaToks i o baseSign) [1..]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavutypeToks :: Env -> Set.Set String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu Set.map (\ tyId -> showIsaTypeT tyId baseSign) . Map.keysSet . typeMap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavutransSignature :: Env -> Set.Set String -> Result Isa.Sign
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavutransSignature env toks = do
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu let extractTypeName tyId typeInfo m =
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu let getTypeArgs n k = case k of
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu ClassKind _ -> []
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu FunKind _ _ r _ ->
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu (TFree ("'a" ++ show n) [], [isaTerm])
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu : getTypeArgs (n + 1) r
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu in Map.insert (showIsaTypeT tyId baseSign)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu [(isaTerm, getTypeArgs (1 :: Int) $ typeKind typeInfo)] m
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu ct <- transAssumps (globAnnos env) toks $ assumps env
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu { baseSig = baseSign
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu -- translation of typeconstructors
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu , tsig = emptyTypeSig
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu { arities = Map.foldWithKey extractTypeName Map.empty
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu (typeMap env) }
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu , constTab = ct }
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- * translation of a type in an operation declaration
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuunitTyp :: Typ
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuunitTyp = Type "unit" holType []
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavumkPartialType :: Typ -> Typ
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavumkPartialType arg = Type "partial" [] [arg]
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavutransFunType :: FunType -> Typ
transDataEntries :: Env -> Set.Set String
ntys = map (Isa.typeId . fst) des
if Set.member i s then
else return $ Set.insert i s)
transDataEntry :: Env -> Set.Set String -> DataEntry -> Result DomainEntry
Le.Free -> do
nalts <- mapM (transAltDefn env tyToks dp) $ Set.toList alts
-- datatype alternatives/constructors
transAltDefn :: Env -> Set.Set String -> DataPat -> AltDefn
transVar :: Set.Set String -> Id -> VName
renVar t = if Set.member t toks then renVar $ "X_" ++ t else t
-> Result Isa.Sentence
Le.Formula trm -> do
transTerm sign tyToks (getAssumpsToks $ assumps sign) Set.empty trm
transOpId :: Env -> Set.Set String -> Id -> TypeScheme -> VName
ops <- Map.lookup op (assumps sign)
i <- elemIndex ts $ map opType $ Set.toList ops
then Set.insert (getQualVar pat) pVars
isQualVar :: As.Term -> Bool
getQualVar :: As.Term -> VarDecl
ifImplOp :: Isa.Term
unitOp :: Isa.Term
noneOp :: Isa.Term
whenElseOp :: Isa.Term
resOp :: Isa.Term
uncurryOp :: Isa.Term
curryOp :: Isa.Term
return ( if Set.member vd pVars then makePartialVal fTy else fTy
, Isa.Free $ transVar toks var)
instfTy <- funType $ substGen (if null is then Map.empty else
Map.fromList $ zipWith (\ (TypeArg _ _ _ _ i _ _) t
$ Abs (Isa.Free $ transVar toks var)
LetTerm As.Let peqs body _ -> do
mapFun :: MapFun -> Isa.Term
compOp :: Isa.Term
convFun :: ConvFun -> Isa.Term
lift2bool, lift2partial, mkPartial :: Isa.Term
existEqualOp :: Isa.Term
strongEqualOp :: Isa.Term
unpackOp :: FunType -> Isa.Term
isLifted :: Isa.Term -> Bool
flipOp :: Isa.Term
-> Isa.Term -- variable
-> Isa.Term -- simplified application to variable
-> Isa.Term -- simplified argument
-> State Int Isa.Term
mkTermAppl mkPartial $ Isa.Let eqs arg
_ -> Isa.Let eqs inTrm
isPatternType :: As.Term -> Bool
-> Result (FunType, Isa.Term)
p@(ty, _) <- transTerm sign tyToks toks Set.empty pat