@@ -89,15 +89,11 @@ isRelationAtomType _ = False
8989type AttributeName = StringType
9090
9191-- | 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)
9393
9494instance Hashable Attribute where
9595 hashWithSalt salt (Attribute attrName _) = hashWithSalt salt attrName
9696
97−instance NFData Attribute where rnf = genericRnf
98−
99−instance Binary Attribute
100−
10197-- | 'Attributes' represent the head of a relation.
10298type Attributes = V.Vector Attribute
10399
@@ -210,10 +206,10 @@ data RelationalExprBase a =
210206 NotEquals (RelationalExprBase a) (RelationalExprBase a) |
211207 Extend (ExtendTupleExprBase a) (RelationalExprBase a)
212208 --Summarize :: AtomExpr -> AttributeName -> RelationalExpr -> RelationalExpr -> RelationalExpr -- a special case of Extend
213− deriving (Show, Eq, Generic)
209+ deriving (Show, Eq, Generic, NFData)
210+
211+instance Binary RelationalExpr
214212
215−instance Binary RelationalExpr
216−
217213type NotificationName = StringType
218214type Notifications = M.Map NotificationName Notification
219215
@@ -222,7 +218,7 @@ data Notification = Notification {
222218 changeExpr :: RelationalExpr,
223219 reportExpr :: RelationalExpr
224220 }
225− deriving (Show, Eq, Binary, Generic)
221+ deriving (Show, Eq, Binary, Generic, NFData)
226222
227223type TypeVarName = StringType
228224
@@ -248,7 +244,7 @@ type DataConstructorName = StringType
248244type AtomTypeName = StringType
249245
250246-- | 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)
252248
253249type DataConstructorDefs = [DataConstructorDef]
254250
@@ -286,12 +282,12 @@ data DatabaseContext = DatabaseContext {
286282 dbcFunctions :: DatabaseContextFunctions,
287283 notifications :: Notifications,
288284 typeConstructorMapping :: TypeConstructorMapping
289− }
285+ } deriving (NFData, Generic)
290286
291287type IncDepName = StringType
292288
293289-- | 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)
295291
296292instance Binary InclusionDependency
297293
@@ -343,7 +339,7 @@ data RestrictionPredicateExprBase a =
343339 RelationalExprPredicate (RelationalExprBase a) | --type must be same as true and false relations (no attributes)
344340 AtomExprPredicate (AtomExprBase a) | --atom must evaluate to boolean
345341 AttributeEqualityPredicate AttributeName (AtomExprBase a) -- relationalexpr must result in relation with single tuple
346− deriving (Show, Eq, Generic)
342+ deriving (Show, Eq, Generic, NFData)
347343
348344instance Binary RestrictionPredicateExpr
349345
@@ -399,13 +395,13 @@ data AtomExprBase a = AttributeAtomExpr AttributeName |
399395 FunctionAtomExpr AtomFunctionName [AtomExprBase a] a |
400396 RelationAtomExpr (RelationalExprBase a) |
401397 ConstructedAtomExpr DataConstructorName [AtomExprBase a] a
402− deriving (Eq,Show,Generic)
398+ deriving (Eq,Show,Generic, NFData)
403399
404400instance Binary AtomExpr
405401
406402-- | Used in tuple creation when creating a relation.
407403data ExtendTupleExprBase a = AttributeExtendTupleExpr AttributeName (AtomExprBase a)
408− deriving (Show, Eq, Generic)
404+ deriving (Show, Eq, Generic, NFData)
409405
410406type ExtendTupleExpr = ExtendTupleExprBase ()
411407
@@ -421,6 +417,9 @@ type AtomFunctionBodyScript = StringType
421417type AtomFunctionBodyType = [Atom] -> Atom
422418
423419data AtomFunctionBody = AtomFunctionBody (Maybe AtomFunctionBodyScript) AtomFunctionBodyType
420+
421+instance NFData AtomFunctionBody where
422+ rnf (AtomFunctionBody mScript _) = rnf mScript
424423
425424instance Show AtomFunctionBody where
426425 show (AtomFunctionBody mScript _) = case mScript of
@@ -432,24 +431,13 @@ data AtomFunction = AtomFunction {
432431 atomFuncName :: AtomFunctionName,
433432 atomFuncType :: [AtomType],
434433 atomFuncBody :: AtomFunctionBody
435− }
434+ } deriving (Generic, NFData)
436435
437436instance Hashable AtomFunction where
438437 hashWithSalt salt func = salt `hashWithSalt` (atomFuncName func)
439438
440439instance Eq AtomFunction where
441− f1 == f2 = let (AtomFunctionBody mScript1 _) = atomFuncBody f1
442− (AtomFunctionBody mScript2 _) = atomFuncBody f2 in
443− if atomFuncName f1 == atomFuncName f2 then
444− if isJust mScript1 then
445− if mScript1 == mScript2 then
446− True
447− else
448− False
449− else
450− True
451− else
452− False
440+ f1 == f2 = atomFuncName f1 == atomFuncName f2
453441
454442instance Show AtomFunction where
455443 show aFunc = unpack (atomFuncName aFunc) ++ "::" ++ showArgTypes ++ "; " ++ body
@@ -462,10 +450,8 @@ data AttributeNames = AttributeNames (S.Set AttributeName) |
462450 InvertedAttributeNames (S.Set AttributeName) |
463451 UnionAttributeNames AttributeNames AttributeNames |
464452 IntersectAttributeNames AttributeNames AttributeNames
465− deriving (Eq, Show, Generic)
453+ deriving (Eq, Show, Generic, Binary, NFData)
466454
467−instance Binary AttributeNames
468−
469455-- | The persistence strategy is a global database option which represents how to persist the database in the filesystem, if at all.
470456data PersistenceStrategy = NoPersistence | -- ^ no filesystem persistence/memory-only database
471457 MinimalPersistence FilePath | -- ^ fsync off, not crash-safe
@@ -476,12 +462,12 @@ type AttributeExpr = AttributeExprBase ()
476462
477463data AttributeExprBase a = AttributeAndTypeNameExpr AttributeName TypeConstructor a |
478464 NakedAttributeExpr Attribute
479− deriving (Eq, Show, Generic, Binary)
465+ deriving (Eq, Show, Generic, Binary, NFData)
480466
481467data TupleExprBase a = TupleExpr (M.Map AttributeName (AtomExprBase a))
482− deriving (Eq, Show, Generic)
468+ deriving (Eq, Show, Generic, NFData)
483469
484−instance Binary TupleExpr
470+instance Binary TupleExpr
485471
486472type TupleExpr = TupleExprBase ()
487473
@@ -500,13 +486,16 @@ type DatabaseContextFunctionBodyScript = StringType
500486
501487type DatabaseContextFunctionBodyType = [Atom] -> DatabaseContext -> DatabaseContext
502488
503−data DatabaseContextFunctionBody = DatabaseContextFunctionBody (Maybe DatabaseContextFunctionBodyScript) DatabaseContextFunctionBodyType
489+data DatabaseContextFunctionBody = DatabaseContextFunctionBody (Maybe DatabaseContextFunctionBodyScript) DatabaseContextFunctionBodyType
490+
491+instance NFData DatabaseContextFunctionBody where
492+ rnf (DatabaseContextFunctionBody mScript _) = rnf mScript
504493
505494data DatabaseContextFunction = DatabaseContextFunction {
506495 dbcFuncName :: DatabaseContextFunctionName,
507496 dbcFuncType :: [AtomType],
508497 dbcFuncBody :: DatabaseContextFunctionBody
509− }
498+ } deriving (Generic, NFData)
510499
511500type DatabaseContextFunctions = HS.HashSet DatabaseContextFunction
512501
@@ -514,15 +503,4 @@ instance Hashable DatabaseContextFunction where
514503 hashWithSalt salt func = salt `hashWithSalt` (dbcFuncName func)
515504
516505instance Eq DatabaseContextFunction where
517− f1 == f2 = let (DatabaseContextFunctionBody mScript1 _) = dbcFuncBody f1
518− (DatabaseContextFunctionBody mScript2 _) = dbcFuncBody f2 in
519− if dbcFuncName f1 == dbcFuncName f2 then
520− if isJust mScript1 then
521− if mScript1 == mScript2 then
522− True
523− else
524− False
525− else
526− True
527− else
528− False
506+ f1 == f2 = dbcFuncName f1 == dbcFuncName f2