Morphism.hs revision 67086e0fe40a985c5e8a3cf50e611f43234580c2
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederModule : $Header$
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederDescription : morphisms implementation
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederCopyright : (c) Christian Maeder and Uni Bremen 2002-2006
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederMaintainer : Christian.Maeder@dfki.de
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederStability : provisional
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaederPortability : portable
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maedermapping entities of morphisms
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederimport qualified Data.Map as Map
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maederinstance Eq Morphism where
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder m1 == m2 = (msource m1, mtarget m1, typeIdMap m1, funMap m1) ==
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder (msource m2, mtarget m2, typeIdMap m2, funMap m2)
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder-- | map type and expand it
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapTypeE :: TypeMap -> IdMap -> Type -> Type
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapTypeE tm im = expandAliases tm . mapType im
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapTypeScheme :: TypeMap -> IdMap -> TypeScheme -> TypeScheme
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapTypeScheme tm im = mapTypeOfScheme $ mapTypeE tm im
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapSen :: TypeMap -> IdMap -> FunMap -> Term -> Term
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapSen tm im fm = mapTerm (mapFunSym tm im fm, mapTypeE tm im)
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapDataEntry :: TypeMap -> IdMap -> FunMap -> DataEntry -> DataEntry
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapDataEntry tm im fm (DataEntry dm i k args rk alts) =
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder let tim = compIdMap dm im
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder in DataEntry tim i k args rk $ map
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder (mapAlt tm tim fm args $ patToType (Map.findWithDefault i i tim)
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder args rk) alts
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapAlt :: TypeMap -> IdMap -> FunMap -> [TypeArg] -> Type -> AltDefn
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian MaedermapAlt tm im fm args dt c@(Construct mi ts p sels) =
4654dbb45f8a4aea7aa5fed6be22c9efff19bfcaChristian Maeder let sc = TypeScheme args
in Map.findWithDefault (i, msc) (i, msc) fm
compIdMap im1 im2 = Map.foldWithKey ( \ i j ->
let k = Map.findWithDefault j j im2 in
if i == k then id else Map.insert i k)
{ typeIdMap = Map.intersection im $ typeMap src
if p1 == p3 then id else Map.insert p1 p3)
fm2 $ funMap m1) $ Map.fromList $
$ Map.toList $ assumps src
all (`elem` (Map.keys $ typeMap s))
(Map.keys ts)
&& all (`elem` (Map.keys $ typeMap t))
(Map.elems ts)
&& all ((`elem` (Map.keys $ assumps s)) . fst)
(Map.keys fs)
&& all ((`elem` (Map.keys $ assumps t)) . fst)
(Map.elems fs)
tm1 = Map.toList $ typeIdMap m1
tm2 = Map.toList $ typeIdMap m2
ut1 = Map.keys (typeMap s1) \\ map fst tm1
ut2 = Map.keys (typeMap s2) \\ map fst tm2
fm1 = Map.toList $ funMap m1
fm2 = Map.toList $ funMap m2
map ( \ o -> (i, opType o)) $ opInfos os) . Map.toList
case Map.lookup i m of
Nothing -> return $ Map.insert i j m
(return Map.empty) tml
case Map.lookup nisc m of
Nothing -> return $ Map.insert nisc
(return Map.empty) fml
{ typeIdMap = Map.filterWithKey (/=) tm
, funMap = Map.filterWithKey (/=) fm }
typeSymMap = Map.foldWithKey ( \ i ti ->
let j = Map.findWithDefault i i im
in Map.insert (idToTypeSymbol src i k)
$ idToTypeSymbol tar j k) Map.empty $ typeMap src
in Map.insert (idToOpSymbol src i ty)