@@ -3,6 +3,7 @@
3module ProjectM36.Base where
3module ProjectM36.Base where
4import ProjectM36.DatabaseContextFunctionError
4import ProjectM36.DatabaseContextFunctionError
5import ProjectM36.AtomFunctionError
5import ProjectM36.AtomFunctionError
6+import ProjectM36.TupleFunctionError
7import qualified Data.Map as M
8import qualified Data.Map as M
8import qualified Data.HashSet as HS
9import qualified Data.HashSet as HS
@@ -35,9 +36,12 @@ data Atom = IntAtom Int |
35 ByteStringAtom ByteString |
36 ByteStringAtom ByteString |
36 BoolAtom Bool |
37 BoolAtom Bool |
37 RelationAtom Relation |
38 RelationAtom Relation |
38− ConstructedAtom DataConstructorName AtomType [Atom]
39+ ConstructedAtom DataConstructorName AtomType [Atom] |
40+ TupleFunctionAtom TupleFunctionName -- a function stored as an atom that runs on the current tuple
39 deriving (Eq, Show, Binary, Typeable, NFData, Generic)
41 deriving (Eq, Show, Binary, Typeable, NFData, Generic)
43+type TupleFunctionName = StringType
41instance Hashable Atom where
45instance Hashable Atom where
42 hashWithSalt salt (ConstructedAtom dConsName _ atoms) = salt `hashWithSalt` atoms
46 hashWithSalt salt (ConstructedAtom dConsName _ atoms) = salt `hashWithSalt` atoms
43 `hashWithSalt` dConsName --AtomType is not hashable
47 `hashWithSalt` dConsName --AtomType is not hashable
@@ -49,6 +53,7 @@ instance Hashable Atom where
49 hashWithSalt salt (ByteStringAtom bs) = salt `hashWithSalt` bs
53 hashWithSalt salt (ByteStringAtom bs) = salt `hashWithSalt` bs
50 hashWithSalt salt (BoolAtom b) = salt `hashWithSalt` b
54 hashWithSalt salt (BoolAtom b) = salt `hashWithSalt` b
51 hashWithSalt salt (RelationAtom r) = salt `hashWithSalt` r
55 hashWithSalt salt (RelationAtom r) = salt `hashWithSalt` r
56+ hashWithSalt salt (TupleFunctionAtom nam) = salt `hashWithSalt` nam
53instance Binary UTCTime where
58instance Binary UTCTime where
54 put utc = put $ toRational (utcTimeToPOSIXSeconds utc)
59 put utc = put $ toRational (utcTimeToPOSIXSeconds utc)
@@ -73,6 +78,7 @@ data AtomType = IntAtomType |
73 BoolAtomType |
78 BoolAtomType |
74 RelationAtomType Attributes |
79 RelationAtomType Attributes |
75 ConstructedAtomType TypeConstructorName TypeVarMap |
80 ConstructedAtomType TypeConstructorName TypeVarMap |
81+ TupleFunctionAtomType |
76 TypeVariableType TypeVarName
82 TypeVariableType TypeVarName
77 --wildcard used in Atom Functions and tuples for data constructors which don't provide all arguments to the type constructor
83 --wildcard used in Atom Functions and tuples for data constructors which don't provide all arguments to the type constructor
78 deriving (Eq, NFData, Generic, Binary, Show)
84 deriving (Eq, NFData, Generic, Binary, Show)
@@ -273,6 +279,15 @@ data SchemaIsomorph = IsoRestrict RelVarName RestrictionPredicateExpr (RelVarNam
273 deriving (Generic, Binary, Show)
279 deriving (Generic, Binary, Show)
275type SchemaIsomorphs = [SchemaIsomorph]
281type SchemaIsomorphs = [SchemaIsomorph]
283+type TupleFunctionScript = StringType
285+type TupleFunctionBodyType = RelationTuple -> Either TupleFunctionError Atom
287+data TupleFunction = TupleFunction (Maybe TupleFunctionScript) TupleFunctionBodyType
288+ deriving (Generic, NFData)
290+type TupleFunctions = M.Map TupleFunctionName TupleFunction
277data DatabaseContext = DatabaseContext {
292data DatabaseContext = DatabaseContext {
278 inclusionDependencies :: InclusionDependencies,
293 inclusionDependencies :: InclusionDependencies,
@@ -280,7 +295,8 @@ data DatabaseContext = DatabaseContext {
280 atomFunctions :: AtomFunctions,
295 atomFunctions :: AtomFunctions,
281 dbcFunctions :: DatabaseContextFunctions,
296 dbcFunctions :: DatabaseContextFunctions,
282 notifications :: Notifications,
297 notifications :: Notifications,
283− typeConstructorMapping :: TypeConstructorMapping
298+ typeConstructorMapping :: TypeConstructorMapping,
299+ tupleFunctions :: TupleFunctions
284 } deriving (NFData, Generic)
300 } deriving (NFData, Generic)
286type IncDepName = StringType
302type IncDepName = StringType