@@ -3,6 +3,7 @@
33module ProjectM36.Base where
44import ProjectM36.DatabaseContextFunctionError
55import ProjectM36.AtomFunctionError
6+import ProjectM36.TupleFunctionError
67
78import qualified Data.Map as M
89import qualified Data.HashSet as HS
@@ -35,9 +36,12 @@ data Atom = IntAtom Int |
3536 ByteStringAtom ByteString |
3637 BoolAtom Bool |
3738 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
3941 deriving (Eq, Show, Binary, Typeable, NFData, Generic)
4042
43+type TupleFunctionName = StringType
44+
4145instance Hashable Atom where
4246 hashWithSalt salt (ConstructedAtom dConsName _ atoms) = salt `hashWithSalt` atoms
4347 `hashWithSalt` dConsName --AtomType is not hashable
@@ -49,6 +53,7 @@ instance Hashable Atom where
4953 hashWithSalt salt (ByteStringAtom bs) = salt `hashWithSalt` bs
5054 hashWithSalt salt (BoolAtom b) = salt `hashWithSalt` b
5155 hashWithSalt salt (RelationAtom r) = salt `hashWithSalt` r
56+ hashWithSalt salt (TupleFunctionAtom nam) = salt `hashWithSalt` nam
5257
5358instance Binary UTCTime where
5459 put utc = put $ toRational (utcTimeToPOSIXSeconds utc)
@@ -73,6 +78,7 @@ data AtomType = IntAtomType |
7378 BoolAtomType |
7479 RelationAtomType Attributes |
7580 ConstructedAtomType TypeConstructorName TypeVarMap |
81+ TupleFunctionAtomType |
7682 TypeVariableType TypeVarName
7783 --wildcard used in Atom Functions and tuples for data constructors which don't provide all arguments to the type constructor
7884 deriving (Eq, NFData, Generic, Binary, Show)
@@ -273,6 +279,15 @@ data SchemaIsomorph = IsoRestrict RelVarName RestrictionPredicateExpr (RelVarNam
273279 deriving (Generic, Binary, Show)
274280
275281type SchemaIsomorphs = [SchemaIsomorph]
282+
283+type TupleFunctionScript = StringType
284+
285+type TupleFunctionBodyType = RelationTuple -> Either TupleFunctionError Atom
286+
287+data TupleFunction = TupleFunction (Maybe TupleFunctionScript) TupleFunctionBodyType
288+ deriving (Generic, NFData)
289+
290+type TupleFunctions = M.Map TupleFunctionName TupleFunction
276291
277292data DatabaseContext = DatabaseContext {
278293 inclusionDependencies :: InclusionDependencies,
@@ -280,7 +295,8 @@ data DatabaseContext = DatabaseContext {
280295 atomFunctions :: AtomFunctions,
281296 dbcFunctions :: DatabaseContextFunctions,
282297 notifications :: Notifications,
283− typeConstructorMapping :: TypeConstructorMapping
298+ typeConstructorMapping :: TypeConstructorMapping,
299+ tupleFunctions :: TupleFunctions
284300 } deriving (NFData, Generic)
285301
286302type IncDepName = StringType