@@ -89,15 +89,11 @@ isRelationAtomType _ = False
89type AttributeName = StringType
89type AttributeName = StringType
91-- | A relation's type is composed of attribute names and types.
91-- | A relation's type is composed of attribute names and types.
92−data Attribute = Attribute AttributeName AtomType deriving (Eq, Show, Generic)
92+data Attribute = Attribute AttributeName AtomType deriving (Eq, Show, Generic, NFData, Binary)
94instance Hashable Attribute where
94instance Hashable Attribute where
95 hashWithSalt salt (Attribute attrName _) = hashWithSalt salt attrName
95 hashWithSalt salt (Attribute attrName _) = hashWithSalt salt attrName
97−instance NFData Attribute where rnf = genericRnf
99−instance Binary Attribute
101-- | 'Attributes' represent the head of a relation.
97-- | 'Attributes' represent the head of a relation.
102type Attributes = V.Vector Attribute
98type Attributes = V.Vector Attribute
@@ -210,10 +206,10 @@ data RelationalExprBase a =
210 NotEquals (RelationalExprBase a) (RelationalExprBase a) |
206 NotEquals (RelationalExprBase a) (RelationalExprBase a) |
211 Extend (ExtendTupleExprBase a) (RelationalExprBase a)
207 Extend (ExtendTupleExprBase a) (RelationalExprBase a)
212 --Summarize :: AtomExpr -> AttributeName -> RelationalExpr -> RelationalExpr -> RelationalExpr -- a special case of Extend
208 --Summarize :: AtomExpr -> AttributeName -> RelationalExpr -> RelationalExpr -> RelationalExpr -- a special case of Extend
213− deriving (Show, Eq, Generic)
209+ deriving (Show, Eq, Generic, NFData)
211+instance Binary RelationalExpr
215−instance Binary RelationalExpr
217type NotificationName = StringType
213type NotificationName = StringType
218type Notifications = M.Map NotificationName Notification
214type Notifications = M.Map NotificationName Notification
@@ -222,7 +218,7 @@ data Notification = Notification {
222 changeExpr :: RelationalExpr,
218 changeExpr :: RelationalExpr,
223 reportExpr :: RelationalExpr
219 reportExpr :: RelationalExpr
225− deriving (Show, Eq, Binary, Generic)
221+ deriving (Show, Eq, Binary, Generic, NFData)
227type TypeVarName = StringType
223type TypeVarName = StringType
@@ -248,7 +244,7 @@ type DataConstructorName = StringType
248type AtomTypeName = StringType
244type AtomTypeName = StringType
250-- | Used to define a data constructor in a type constructor context. (Left a | Right b)
246-- | Used to define a data constructor in a type constructor context. (Left a | Right b)
251−data DataConstructorDef = DataConstructorDef DataConstructorName [DataConstructorDefArg] deriving (Eq, Show, Binary, Generic)
247+data DataConstructorDef = DataConstructorDef DataConstructorName [DataConstructorDefArg] deriving (Eq, Show, Binary, Generic, NFData)
253type DataConstructorDefs = [DataConstructorDef]
249type DataConstructorDefs = [DataConstructorDef]
@@ -286,12 +282,12 @@ data DatabaseContext = DatabaseContext {
286 dbcFunctions :: DatabaseContextFunctions,
282 dbcFunctions :: DatabaseContextFunctions,
287 notifications :: Notifications,
283 notifications :: Notifications,
288 typeConstructorMapping :: TypeConstructorMapping
284 typeConstructorMapping :: TypeConstructorMapping
289− }
285+ } deriving (NFData, Generic)
291type IncDepName = StringType
287type IncDepName = StringType
293-- | Inclusion dependencies represent every possible database constraints. Constraints enforce specific, arbitrarily-complex rules to which the database context must adhere.
289-- | Inclusion dependencies represent every possible database constraints. Constraints enforce specific, arbitrarily-complex rules to which the database context must adhere.
294−data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq, Generic)
290+data InclusionDependency = InclusionDependency RelationalExpr RelationalExpr deriving (Show, Eq, Generic, NFData)
296instance Binary InclusionDependency
292instance Binary InclusionDependency
@@ -343,7 +339,7 @@ data RestrictionPredicateExprBase a =
343 RelationalExprPredicate (RelationalExprBase a) | --type must be same as true and false relations (no attributes)
339 RelationalExprPredicate (RelationalExprBase a) | --type must be same as true and false relations (no attributes)
344 AtomExprPredicate (AtomExprBase a) | --atom must evaluate to boolean
340 AtomExprPredicate (AtomExprBase a) | --atom must evaluate to boolean
345 AttributeEqualityPredicate AttributeName (AtomExprBase a) -- relationalexpr must result in relation with single tuple
341 AttributeEqualityPredicate AttributeName (AtomExprBase a) -- relationalexpr must result in relation with single tuple
346− deriving (Show, Eq, Generic)
342+ deriving (Show, Eq, Generic, NFData)
348instance Binary RestrictionPredicateExpr
344instance Binary RestrictionPredicateExpr
@@ -399,13 +395,13 @@ data AtomExprBase a = AttributeAtomExpr AttributeName |
399 FunctionAtomExpr AtomFunctionName [AtomExprBase a] a |
395 FunctionAtomExpr AtomFunctionName [AtomExprBase a] a |
400 RelationAtomExpr (RelationalExprBase a) |
396 RelationAtomExpr (RelationalExprBase a) |
401 ConstructedAtomExpr DataConstructorName [AtomExprBase a] a
397 ConstructedAtomExpr DataConstructorName [AtomExprBase a] a
402− deriving (Eq,Show,Generic)
398+ deriving (Eq,Show,Generic, NFData)
404instance Binary AtomExpr
400instance Binary AtomExpr
406-- | Used in tuple creation when creating a relation.
402-- | Used in tuple creation when creating a relation.
407data ExtendTupleExprBase a = AttributeExtendTupleExpr AttributeName (AtomExprBase a)
403data ExtendTupleExprBase a = AttributeExtendTupleExpr AttributeName (AtomExprBase a)
408− deriving (Show, Eq, Generic)
404+ deriving (Show, Eq, Generic, NFData)
410type ExtendTupleExpr = ExtendTupleExprBase ()
406type ExtendTupleExpr = ExtendTupleExprBase ()
@@ -421,6 +417,9 @@ type AtomFunctionBodyScript = StringType
421type AtomFunctionBodyType = [Atom] -> Atom
417type AtomFunctionBodyType = [Atom] -> Atom
423data AtomFunctionBody = AtomFunctionBody (Maybe AtomFunctionBodyScript) AtomFunctionBodyType
419data AtomFunctionBody = AtomFunctionBody (Maybe AtomFunctionBodyScript) AtomFunctionBodyType
421+instance NFData AtomFunctionBody where
422+ rnf (AtomFunctionBody mScript _) = rnf mScript
425instance Show AtomFunctionBody where
424instance Show AtomFunctionBody where
426 show (AtomFunctionBody mScript _) = case mScript of
425 show (AtomFunctionBody mScript _) = case mScript of
@@ -432,24 +431,13 @@ data AtomFunction = AtomFunction {
432 atomFuncName :: AtomFunctionName,
431 atomFuncName :: AtomFunctionName,
433 atomFuncType :: [AtomType],
432 atomFuncType :: [AtomType],
434 atomFuncBody :: AtomFunctionBody
433 atomFuncBody :: AtomFunctionBody
435− }
434+ } deriving (Generic, NFData)
437instance Hashable AtomFunction where
436instance Hashable AtomFunction where
438 hashWithSalt salt func = salt `hashWithSalt` (atomFuncName func)
437 hashWithSalt salt func = salt `hashWithSalt` (atomFuncName func)
440instance Eq AtomFunction where
439instance Eq AtomFunction where
441− f1 == f2 = let (AtomFunctionBody mScript1 _) = atomFuncBody f1
442− (AtomFunctionBody mScript2 _) = atomFuncBody f2 in
443− if atomFuncName f1 == atomFuncName f2 then
440+ f1 == f2 = atomFuncName f1 == atomFuncName f2
444− if isJust mScript1 then
445− if mScript1 == mScript2 then
454instance Show AtomFunction where
442instance Show AtomFunction where
455 show aFunc = unpack (atomFuncName aFunc) ++ "::" ++ showArgTypes ++ "; " ++ body
443 show aFunc = unpack (atomFuncName aFunc) ++ "::" ++ showArgTypes ++ "; " ++ body
@@ -462,10 +450,8 @@ data AttributeNames = AttributeNames (S.Set AttributeName) |
462 InvertedAttributeNames (S.Set AttributeName) |
450 InvertedAttributeNames (S.Set AttributeName) |
463 UnionAttributeNames AttributeNames AttributeNames |
451 UnionAttributeNames AttributeNames AttributeNames |
464 IntersectAttributeNames AttributeNames AttributeNames
452 IntersectAttributeNames AttributeNames AttributeNames
465− deriving (Eq, Show, Generic)
453+ deriving (Eq, Show, Generic, Binary, NFData)
467−instance Binary AttributeNames
469-- | The persistence strategy is a global database option which represents how to persist the database in the filesystem, if at all.
455-- | The persistence strategy is a global database option which represents how to persist the database in the filesystem, if at all.
470data PersistenceStrategy = NoPersistence | -- ^ no filesystem persistence/memory-only database
456data PersistenceStrategy = NoPersistence | -- ^ no filesystem persistence/memory-only database
471 MinimalPersistence FilePath | -- ^ fsync off, not crash-safe
457 MinimalPersistence FilePath | -- ^ fsync off, not crash-safe
@@ -476,12 +462,12 @@ type AttributeExpr = AttributeExprBase ()
477data AttributeExprBase a = AttributeAndTypeNameExpr AttributeName TypeConstructor a |
463data AttributeExprBase a = AttributeAndTypeNameExpr AttributeName TypeConstructor a |
478 NakedAttributeExpr Attribute
464 NakedAttributeExpr Attribute
479− deriving (Eq, Show, Generic, Binary)
465+ deriving (Eq, Show, Generic, Binary, NFData)
481data TupleExprBase a = TupleExpr (M.Map AttributeName (AtomExprBase a))
467data TupleExprBase a = TupleExpr (M.Map AttributeName (AtomExprBase a))
482− deriving (Eq, Show, Generic)
468+ deriving (Eq, Show, Generic, NFData)
484−instance Binary TupleExpr
470+instance Binary TupleExpr
486type TupleExpr = TupleExprBase ()
472type TupleExpr = TupleExprBase ()
@@ -500,13 +486,16 @@ type DatabaseContextFunctionBodyScript = StringType
501type DatabaseContextFunctionBodyType = [Atom] -> DatabaseContext -> DatabaseContext
487type DatabaseContextFunctionBodyType = [Atom] -> DatabaseContext -> DatabaseContext
503−data DatabaseContextFunctionBody = DatabaseContextFunctionBody (Maybe DatabaseContextFunctionBodyScript) DatabaseContextFunctionBodyType
489+data DatabaseContextFunctionBody = DatabaseContextFunctionBody (Maybe DatabaseContextFunctionBodyScript) DatabaseContextFunctionBodyType
491+instance NFData DatabaseContextFunctionBody where
492+ rnf (DatabaseContextFunctionBody mScript _) = rnf mScript
505data DatabaseContextFunction = DatabaseContextFunction {
494data DatabaseContextFunction = DatabaseContextFunction {
506 dbcFuncName :: DatabaseContextFunctionName,
495 dbcFuncName :: DatabaseContextFunctionName,
507 dbcFuncType :: [AtomType],
496 dbcFuncType :: [AtomType],
508 dbcFuncBody :: DatabaseContextFunctionBody
497 dbcFuncBody :: DatabaseContextFunctionBody
509− }
498+ } deriving (Generic, NFData)
511type DatabaseContextFunctions = HS.HashSet DatabaseContextFunction
500type DatabaseContextFunctions = HS.HashSet DatabaseContextFunction
@@ -514,15 +503,4 @@ instance Hashable DatabaseContextFunction where
514 hashWithSalt salt func = salt `hashWithSalt` (dbcFuncName func)
503 hashWithSalt salt func = salt `hashWithSalt` (dbcFuncName func)
516instance Eq DatabaseContextFunction where
505instance Eq DatabaseContextFunction where
517− f1 == f2 = let (DatabaseContextFunctionBody mScript1 _) = dbcFuncBody f1
518− (DatabaseContextFunctionBody mScript2 _) = dbcFuncBody f2 in
519− if dbcFuncName f1 == dbcFuncName f2 then
506+ f1 == f2 = dbcFuncName f1 == dbcFuncName f2
520− if isJust mScript1 then
521− if mScript1 == mScript2 then