4673N/A{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
4673N/ADescription : Program transformations
4673N/ACopyright : (c) Ewaryst Schulz, DFKI Bremen 2010
4673N/AMaintainer : ewaryst.schulz@dfki.de
4673N/APortability : non-portable (various glasgow extensions)
6982N/AProgram transformations from CSL specifications to CAS programs
4673N/Aand utilities for lemma generation
4673N/Aimport Prelude hiding (lookup)
4673N/A{- ----------------------------------------------------------------------
4673N/ADatatypes and Classes for Term- and Program Transformations
4673N/A---------------------------------------------------------------------- -}
4673N/AmkOperator :: String -> [EXTPARAM] -> [EXPRESSION] -> Range -> EXPRESSION
4673N/AmkOperator = mkAndAnalyzeOp ()
4673N/A-- | A class to abstract from the concrete variable generation facility
4673N/Aclass Monad m => VarGen m where
4673N/Ainstance VarGen (State Int) where
4673N/Ainstance VarGen (State (Int, String)) where
4673N/Ainstance VarGen m => VarGen (StateT s m) where
4673N/A-- | A class to construct EXPRESSIONs from simple tuple structures
4673N/Ainstance SExp EXPRESSION where
4673N/A toExp s = mkOperator s [] [] nullRange
4673N/A toOp s = OpDecl (SimpleConstant s) [] [] nullRange
4673N/Ainstance SExp ConstantName where
4673N/A toExp (SimpleConstant s) = mkOperator s [] [] nullRange
4865N/A toExp x = error $ "toExp: elim-constant not supported " ++ show x
4673N/Ainstance SExp a => SExp (String, a) where
4865N/A toExp (s, x) = mkOperator s [] [toExp x] nullRange
4865N/Ainstance SExp a => SExp (ConstantName, [a]) where
4865N/A toExp (n, l) = Op (OpUser n) [] (map toExp l) nullRange
4865N/Ainstance (SExp a, SExp b) => SExp (String, a, b) where
4865N/A toExp (s, x, y) = mkOperator s [] [toExp x, toExp y] nullRange
4865N/Ainstance (SExp a, SExp b, SExp c) => SExp (String, a, b, c) where
4865N/A mkOperator s [] [toExp x, toExp y, toExp z] nullRange
4865N/A{- strangely, ghc says that we would have overlapping instances with
4865N/Ainstance SExp a => SExp (String, a), but I can't see it. I introduce
4865N/Athis strange looking instance -}
4865N/Ainstance (SExp a) => SExp ((), String, [a]) where
4865N/A toExp (_, s, l) = mkOperator s [] (map toExp l) nullRange
4673N/A-- | A class to construct CMDs from simple tuple structures
4673N/Ainstance (SExp a, SExp b) => SCmd (String, a, b) where
4673N/A toCmd (s, x, y) = Cmd s [toExp x, toExp y]
4865N/Ainstance (SOp a, SExp b) => SCmd (a, b) where
4673N/A toCmd (x, y) = Ass (toOp x) $ toExp y
4865N/A toIntervalExp :: a -> EXPRESSION
4673N/Ainstance IntervalLike EXPRESSION where
4865N/Ainstance IntervalLike (Double, Double) where
4865N/A toIntervalExp (a, b) = Interval a b nullRange