Morphism.hs revision 6858f9c9c8b077b2b574a9f30753cf5fec8124d6
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzModule : $Header$
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzDescription : Morphisms for Maude
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzCopyright : (c) Martin Kuehl, Uni Bremen 2008
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzMaintainer : mkhl@informatik.uni-bremen.de
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzStability : experimental
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzPortability : portable
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzDefinition of morphisms for Maude.
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz Morphism(..),
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz fromRenamingSet,
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport Maude.Sign hiding (empty, isLegal)
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport qualified Maude.Sign as Sign (empty, isLegal)
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport Data.Typeable (Typeable)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuimport qualified Data.Map as Map
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuimport qualified Data.Set as Set
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuimport qualified Common.Result as Result
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- for ShATermConvertible
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- for Pretty
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuimport Common.DocUtils (Pretty, pretty)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuimport qualified Common.Doc as Doc
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype SortMap = Map.Map Symbol Symbol
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype OpMap = Map.Map Symbol Symbol
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype LabelMap = Map.Map Symbol Symbol
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savudata Morphism = Morphism {
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu source :: Sign,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu target :: Sign,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu sortMap :: SortMap,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu opMap :: OpMap,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu labelMap :: LabelMap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu } deriving (Show, Eq, Typeable)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- TODO: Add real pretty-printing for Maude Morphisms.
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Pretty Morphism where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- TODO: Replace dummy implementation for ShATermConvertible Morphism.
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance ShATermConvertible Morphism where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu toShATermAux table _ = return (table, 0)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu fromShATermAux _ table = (table, empty)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- | extract a Morphism from a RenamingSet
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavufromRenamingSet :: RenamingSet -> Morphism
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavufromRenamingSet = Set.fold insertRenaming empty
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- | extract a Symbol Map from a Morphism
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavusymbolMap :: Morphism -> SymbolMap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavusymbolMap mor = Map.unions [(sortMap mor), (opMap mor), (labelMap mor)]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- | insert a Renaming into a Morphism
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuinsertRenaming :: Renaming -> Morphism -> Morphism
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuinsertRenaming rename mor = let
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu src = source mor
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu tgt = target mor
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu smap = sortMap mor
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu omap = opMap mor
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu lmap = labelMap mor
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu op nam as cod dom = Op { op'name = nam, op'range = cod, op'domain = dom, op'attrs = as }
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu in case rename of
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu Sort'To {from = a, to = b} -> mor {
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu source = insertSort a src,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu target = insertSort b tgt,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu sortMap = Map.insert a b smap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu Op'To {from = a, to = b} -> mor {
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu source = insertOpName a src,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu target = insertOpName b tgt,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu opMap = Map.insert a b omap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu Op'Type'To {from = a, range = cod, domain = dom, to = b, attrs = as} -> mor {
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu source = insertOp (op a as cod dom) src,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu target = insertOp (op b as cod dom) tgt,
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu opMap = Map.insert a b omap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu Label'To {from = a, to = b} -> mor {
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu labelMap = Map.insert a b lmap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- | the empty Morphism
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuempty :: Morphism
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuempty = identity Sign.empty
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- | the identity Morphism
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuidentity :: Sign -> Morphism
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuidentity sign = Morphism {
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu source = sign,
sortMap = Map.empty,
opMap = Map.empty,
labelMap = Map.empty
compose :: Morphism -> Morphism -> Result.Result Morphism
| (target f) /= (source g) = fail "target of the first and source of the second morphism are different"
apply mp nam = Map.findWithDefault nam nam mp
in if x == y then id else Map.insert x y
compose'map mp items = if Map.null (mp g)
apply mp nam = Map.findWithDefault nam nam mp
legal'source = Sign.isLegal src
legal'target = Sign.isLegal tgt
mapSentence :: Morphism -> Sentence -> Result.Result Sentence