0N/A{-# LANGUAGE OverlappingInstances, TypeSynonymInstances #-}
0N/ADescription : Accessing the Sorts of Maude data types
0N/ACopyright : (c) Martin Kuehl, Uni Bremen 2008-2009
0N/AMaintainer : mkhl@informatik.uni-bremen.de
0N/AStability : experimental
0N/APortability : portable
0N/AAccessing the Sorts of Maude data types.
0N/ADefines a type class 'HasSorts' that lets us access the 'Sort's of Maude
0N/Adata types as 'SymbolSet's.
553N/A -- * The HasSorts type class
-- * The HasSorts type class
-- | Represents something that contains a 'Set' of 'Sort's (as 'Symbol's).
-- | Extract the 'Sort's contained in the input.
getSorts :: a -> SymbolSet
-- | Map the 'Sort's contained in the input.
mapSorts :: SymbolMap -> a -> a
-- * Predefined instances
instance HasSorts Symbol where
getSorts sym = case sym of
Operator _ dom cod -> getSorts (dom, cod)
mapSorts mp sym = case sym of
Sort _ -> mapAsSymbol id mp sym
Kind _ -> mapAsSymbol asKind mp $ asSort sym
Operator qid dom cod -> let
in Operator qid dom' cod'
instance (HasSorts a) => HasSorts [a] where
mapSorts = map . mapSorts
instance (HasSorts a, HasSorts b) => HasSorts (a, b) where
getSorts (a, b) =
Set.union (getSorts a) (getSorts b)
mapSorts mp (a, b) = (mapSorts mp a, mapSorts mp b)
instance (HasSorts a, HasSorts b, HasSorts c) => HasSorts (a, b, c) where
getSorts (a, b, c) =
Set.union (getSorts a) (getSorts (b, c))
mapSorts mp (a, b, c) = (mapSorts mp a, mapSorts mp b, mapSorts mp c)
instance (Ord a, HasSorts a) => HasSorts (Set a) where
instance (Ord a, HasSorts a) => HasSorts (Map k a) where
instance (Ord a, HasSorts a) => HasSorts (Rel a) where
instance HasSorts Sort where
mapSorts = mapAsSymbol $ SortId . getName
instance HasSorts Kind where
mapSorts = mapAsSymbol $ KindId . getName
instance HasSorts Type where
getSorts typ = case typ of
TypeSort sort -> getSorts sort
TypeKind kind -> getSorts kind
mapSorts mp typ = case typ of
TypeSort sort -> TypeSort $ mapSorts mp sort
TypeKind kind -> TypeKind $ mapSorts mp kind
instance HasSorts Operator where
getSorts (Op _ dom cod _) = getSorts (dom, cod)
mapSorts mp (Op op dom cod as) = let
instance HasSorts Attr where
getSorts attr = case attr of
LeftId term -> getSorts term
RightId term -> getSorts term
mapSorts mp attr = case attr of
Id term -> Id $ mapSorts mp term
LeftId term -> LeftId $ mapSorts mp term
RightId term -> RightId $ mapSorts mp term
instance HasSorts Term where
getSorts term = case term of
Const _ tp -> getSorts tp
Apply _ ts tp -> getSorts (ts, tp)
mapSorts mp term = case term of
Const con tp -> Const con (mapSorts mp tp)
Var var tp -> Var var (mapSorts mp tp)
Apply op ts tp -> Apply op (mapSorts mp ts) (mapSorts mp tp)
instance HasSorts Condition where
getSorts cond = case cond of
EqCond t1 t2 -> getSorts (t1, t2)
MbCond t s -> getSorts (t, s)
MatchCond t1 t2 -> getSorts (t1, t2)
RwCond t1 t2 -> getSorts (t1, t2)
mapSorts mp cond = case cond of
EqCond t1 t2 -> EqCond (mapSorts mp t1) (mapSorts mp t2)
MbCond t s -> MbCond (mapSorts mp t) (mapSorts mp s)
MatchCond t1 t2 -> MatchCond (mapSorts mp t1) (mapSorts mp t2)
RwCond t1 t2 -> RwCond (mapSorts mp t1) (mapSorts mp t2)
instance HasSorts Membership where
getSorts (Mb t s cs _) = getSorts (t, s, cs)
mapSorts mp (Mb t s cs as) = let
instance HasSorts Equation where
getSorts (Eq t1 t2 cs _) = getSorts (t1, t2, cs)
mapSorts mp (Eq t1 t2 cs as) = let
instance HasSorts Rule where
getSorts (Rl t1 t2 cs _) = getSorts (t1, t2, cs)
mapSorts mp (Rl t1 t2 cs as) = let