Grothendieck.der.hs revision c8117ae0b6088d835211e494aef229558c814bd3
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maeder{-# LANGUAGE UndecidableInstances, FlexibleInstances, OverlappingInstances #-}
75a6279dbae159d018ef812185416cf6df386c10Till MossakowskiDescription : manually created ShATermConvertible instances
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederCopyright : (c) Felix Reckers, C. Maeder, Uni Bremen 2002-2006
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederMaintainer : Christian.Maeder@dfki.de
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaederStability : provisional
c797f343be2f3619bb1f5569753166ec49d27bdbChristian MaederPortability : non-portable (existential types)
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder'ShATermConvertible' instances for data types from "Logic.Grothendieck"
89054b2b95a3f92e78324dc852f3d34704e2ca49Christian Maederimport qualified Common.Lib.SizedList as SizedList
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maederimport qualified Data.IntMap as IntMap
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maederimport qualified Data.Map as Map
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maederimport qualified Data.Set as Set
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder{-! for Common.AS_Annotation.SenAttr derive : ShATermLG !-}
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder{-! for Common.AS_Annotation.Annoted derive : ShATermLG !-}
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder{-! for Logic.Prover.ThmStatus derive : ShATermLG !-}
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder{-! for Common.GlobalAnnotations.GlobalAnnos derive : ShATermLG !-}
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder{-! for Common.Lib.Graph.Gr derive : ShATermLG !-}
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder{-! for Common.Lib.Graph.GrContext derive : ShATermLG !-}
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian Maeder{-! for Common.OrderedMap.ElemWOrd derive : ShATermLG !-}
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder{-! for Common.LibName.LinkPath derive : ShATermLG !-}
b190f5c7cf3ddda73724efe5ce82b9585ed76be1Christian MaederatcLogicLookup :: LogicGraph -> String -> String -> AnyLogic
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederatcLogicLookup lg s l =
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder propagateErrors " atcLogicLookup"
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder $ lookupLogic ("ConvertibleLG " ++ s ++ ":") l lg
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder-- the same class as ShATermConvertible, but allowing a logic graph as input
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maederclass Typeable t => ShATermLG t where
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder toShATermLG :: ATermTable -> t -> IO (ATermTable, Int)
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder fromShATermLG :: LogicGraph -> Int -> ATermTable -> (ATermTable, t)
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaedertoShATermLG' :: ShATermLG t => ATermTable -> t -> IO (ATermTable, Int)
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian MaedertoShATermLG' att t = do
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder m <- getKey k att
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder Nothing -> do
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder (att1, i) <- toShATermLG att t
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder setKey k i att1
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder Just i -> return (att, i)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederfromShATermLG' :: ShATermLG t => LogicGraph -> Int -> ATermTable
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder -> (ATermTable, t)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian MaederfromShATermLG' lg i att = case getATerm' i att of
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder Just d -> (att, d)
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder _ -> case fromShATermLG lg i att of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (attN, t) -> (setATerm' i t attN, t)
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder-- generic undecidable instance
e76e6a43f51438215737d6fc176c89da05bb86daChristian Maederinstance (ShATermConvertible a, Typeable a) => ShATermLG a where
e76e6a43f51438215737d6fc176c89da05bb86daChristian Maeder toShATermLG = toShATermAux
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder fromShATermLG _ = fromShATermAux
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maederinstance ShATermLG G_basic_spec where
e76e6a43f51438215737d6fc176c89da05bb86daChristian Maeder toShATermLG att0 (G_basic_spec lid basic_spec) = do
e76e6a43f51438215737d6fc176c89da05bb86daChristian Maeder (att1, i1) <- toShATermLG' att0 (language_name lid)
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian Maeder (att2, i2) <- toShATermLG' att1 basic_spec
836e72a3c413366ba9801726f3b249c7791cb9caChristian Maeder return $ addATerm (ShAAppl "G_basic_spec" [i1, i2] []) att2
836e72a3c413366ba9801726f3b249c7791cb9caChristian Maeder fromShATermLG lg ix att = case getShATerm ix att of
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder ShAAppl "G_basic_spec" [i1, i2] _ ->
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder case fromShATermLG' lg i1 att of { (att1, i1') ->
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder case atcLogicLookup lg "G_basic_spec" i1' of { Logic lid ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case fromShATermLG' lg i2 att1 of { (att2, i2') ->
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder (att2, G_basic_spec lid i2') }}}
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder u -> fromShATermError "G_basic_spec" u
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maederinstance ShATermLG G_sign where
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder toShATermLG att0 (G_sign lid sign si) = do
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder (att1, i1) <- toShATermLG' att0 (language_name lid)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att2, i2) <- toShATermLG' att1 sign
462ec4b2fa3e0e788eb60dcb4aebc518298f342cChristian Maeder (att3, i3) <- toShATermLG' att2 si
f4741f6b7da52b5417899c8fcbe4349b920b006eChristian Maeder return $ addATerm (ShAAppl "G_sign" [i1, i2, i3] []) att3
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder fromShATermLG lg ix att = case getShATerm ix att of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ShAAppl "G_sign" [i1, i2, i3] _ ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case fromShATermLG' lg i1 att of { (att1, i1') ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case atcLogicLookup lg "G_sign" i1' of { Logic lid ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case fromShATermLG' lg i2 att1 of { (att2, i2') ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case fromShATermLG' lg i3 att2 of { (att3, i3') ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att3, G_sign lid i2' i3') }}}}
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder u -> fromShATermError "G_sign" u
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maederinstance ShATermLG G_symbol where
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder toShATermLG att0 (G_symbol lid symbol) = do
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att1, i1) <- toShATermLG' att0 (language_name lid)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att2, i2) <- toShATermLG' att1 symbol
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder return $ addATerm (ShAAppl "G_symbol" [i1, i2] []) att2
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder fromShATermLG lg ix att = case getShATerm ix att of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ShAAppl "G_symbol" [i1, i2] _ ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case fromShATermLG' lg i1 att of { (att1, i1') ->
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder case atcLogicLookup lg "G_symbol" i1' of { Logic lid ->
04dada28736b4a237745e92063d8bdd49a362debChristian Maeder case fromShATermLG' lg i2 att1 of { (att2, i2') ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att2, G_symbol lid i2') }}}
fc816c737e569f135d8e2f79fc83521c85fae667Christian Maeder u -> fromShATermError "G_symbol" u
04dada28736b4a237745e92063d8bdd49a362debChristian Maederinstance (Ord a, ShATermLG a) => ShATermLG (G_symbolmap a) where
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder toShATermLG att0 (G_symbolmap lid m) = do
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder (att1, i1) <- toShATermLG' att0 (language_name lid)
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder (att2, i2) <- toShATermLG' att1 m
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder return $ addATerm (ShAAppl "G_symbolmap" [i1, i2] []) att2
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder fromShATermLG lg ix att = case getShATerm ix att of
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder ShAAppl "G_symbolmap" [i1, i2] _ ->
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder case fromShATermLG' lg i1 att of { (att1, i1') ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case atcLogicLookup lg "G_symbolmap" i1' of { Logic lid ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case fromShATermLG' lg i2 att1 of { (att2, i2') ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att2, G_symbolmap lid i2') }}}
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder u -> fromShATermError "G_symbolmap" u
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maederinstance (Ord a, ShATermLG a) => ShATermLG (G_mapofsymbol a) where
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder toShATermLG att0 (G_mapofsymbol lid m) = do
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder (att1, i1) <- toShATermLG' att0 (language_name lid)
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder (att2, i2) <- toShATermLG' att1 m
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder return $ addATerm (ShAAppl "G_mapofsymbol" [i1, i2] []) att2
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder fromShATermLG lg ix att = case getShATerm ix att of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ShAAppl "G_mapofsymbol" [i1, i2] _ ->
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder case fromShATermLG' lg i1 att of { (att1, i1') ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case atcLogicLookup lg "G_mapofsymbol" i1' of { Logic lid ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case fromShATermLG' lg i2 att1 of { (att2, i2') ->
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder (att2, G_mapofsymbol lid i2') }}}
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder u -> fromShATermError "G_mapofsymbol" u
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maederinstance ShATermLG G_symb_items_list where
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder toShATermLG att0 (G_symb_items_list lid symb_items) = do
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att1, i1) <- toShATermLG' att0 (language_name lid)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att2, i2) <- toShATermLG' att1 symb_items
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder return $ addATerm (ShAAppl "G_symb_items_list" [i1, i2] []) att2
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder fromShATermLG lg ix att = case getShATerm ix att of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ShAAppl "G_symb_items_list" [i1, i2] _ ->
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder case fromShATermLG' lg i1 att of { (att1, i1') ->
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder case atcLogicLookup lg "G_symb_items_list" i1' of { Logic lid ->
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder case fromShATermLG' lg i2 att1 of { (att2, i2') ->
e76e6a43f51438215737d6fc176c89da05bb86daChristian Maeder (att2, G_symb_items_list lid i2') }}}
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder u -> fromShATermError "G_symb_items_list" u
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maederinstance ShATermLG G_symb_map_items_list where
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder toShATermLG att0 (G_symb_map_items_list lid symb_map_items) = do
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder (att1, i1) <- toShATermLG' att0 (language_name lid)
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder (att2, i2) <- toShATermLG' att1 symb_map_items
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder return $ addATerm (ShAAppl "G_symb_map_items_list" [i1, i2] []) att2
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder fromShATermLG lg ix att = case getShATerm ix att of
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder ShAAppl "G_symb_map_items_list" [i1, i2] _ ->
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder case fromShATermLG' lg i1 att of { (att1, i1') ->
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder case atcLogicLookup lg "G_symb_map_items_list" i1'
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder of { Logic lid ->
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder case fromShATermLG' lg i2 att1 of { (att2, i2') ->
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder (att2, G_symb_map_items_list lid i2') }}}
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder u -> fromShATermError "G_symb_map_items_list" u
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maederinstance ShATermLG G_sublogics where
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder toShATermLG att0 (G_sublogics lid sublogics) = do
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder (att1, i1) <- toShATermLG' att0 (language_name lid)
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder (att2, i2) <- toShATermLG' att1 sublogics
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder return $ addATerm (ShAAppl "G_sublogics" [i1, i2] []) att2
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder fromShATermLG lg ix att = case getShATerm ix att of
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder ShAAppl "G_sublogics" [i1, i2] _ ->
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder case fromShATermLG' lg i1 att of { (att1, i1') ->
b984ff0ba75221f64451c1e69b3977967d4e99a1Christian Maeder case atcLogicLookup lg "G_sublogics" i1' of { Logic lid ->
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder case fromShATermLG' lg i2 att1 of { (att2, i2') ->
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder (att2, G_sublogics lid i2') }}}
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maeder u -> fromShATermError "G_sublogics" u
ee9eddfa6953868fd6fbaff0d9ff68675a13675aChristian Maederinstance ShATermLG G_morphism where
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder toShATermLG att0 (G_morphism lid morphism mi) = do
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att1, i1) <- toShATermLG' att0 (language_name lid)
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder (att2, i2) <- toShATermLG' att1 morphism
c797f343be2f3619bb1f5569753166ec49d27bdbChristian Maeder (att3, i3) <- toShATermLG' att2 mi
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder return $ addATerm (ShAAppl "G_morphism" [i1, i2, i3] []) att3
4fb19f237193a3bd6778f8aee3b6dd8da5856665Christian Maeder fromShATermLG lg ix att = case getShATerm ix att of
(att1, propagateErrors "ATC.Grothendieck.AnyComorphism"
case propagateErrors "ATC.Grothendieck.GMorphism"
u -> fromShATermError "Prelude.Maybe" u
instance (Ord a, ShATermLG a) => ShATermLG (Set.Set a) where
(att1, i) <- toShATermLG' att $ Set.toList set
(att1, Set.fromDistinctAscList a') }
u -> fromShATermError "Set.Set" u
instance ShATermLG a => ShATermLG (SizedList.SizedList a) where
toShATermLG att0 = toShATermLG att0 . SizedList.toList
(att, l) -> (att, SizedList.fromList l)
instance (Ord a, ShATermLG a, ShATermLG b) => ShATermLG (Map.Map a b) where
(att1, i) <- toShATermLG' att $ Map.toList fm
(att1, Map.fromDistinctAscList a') }
u -> fromShATermError "Map.Map" u
instance (ShATermLG a) => ShATermLG (IntMap.IntMap a) where
(att1, i) <- toShATermLG' att $ IntMap.toList fm
(att1, IntMap.fromDistinctAscList a') }
u -> fromShATermError "IntMap.IntMap" u