@@ -1,4 +1,4 @@
1−{-# LANGUAGE GADTs #-}
1+{-# LANGUAGE GADTs,DeriveGeneric #-}
2module ProjectM36.Base where
2module ProjectM36.Base where
3import qualified Data.Map as M
3import qualified Data.Map as M
4import qualified Data.HashSet as HS
4import qualified Data.HashSet as HS
@@ -6,17 +6,23 @@ import qualified Data.Hashable as Hash
6import qualified Data.Set as S
6import qualified Data.Set as S
7import Control.Monad.State hiding (join)
7import Control.Monad.State hiding (join)
8import Data.UUID (UUID)
8import Data.UUID (UUID)
9+import Control.DeepSeq (NFData, rnf)
10+import Control.DeepSeq.Generics (genericRnf)
11+import GHC.Generics (Generic)
10data Atom = StringAtom String |
13data Atom = StringAtom String |
11 IntAtom Int |
14 IntAtom Int |
12− RelationAtom Relation deriving (Show, Eq)
15+ RelationAtom Relation deriving (Show, Eq, Generic)
17+instance NFData Atom where rnf = genericRnf
15data AtomType = StringAtomType |
19data AtomType = StringAtomType |
16 IntAtomType |
20 IntAtomType |
17− RelationAtomType Attributes deriving (Eq, Show)
21+ RelationAtomType Attributes deriving (Eq, Show, Generic)
23+instance NFData AtomType where rnf = genericRnf
19−atomTypeForAtom :: Atom -> AtomType
25+atomTypeForAtom :: Atom -> AtomType
20atomTypeForAtom (StringAtom _) = StringAtomType
26atomTypeForAtom (StringAtom _) = StringAtomType
21atomTypeForAtom (IntAtom _) = IntAtomType
27atomTypeForAtom (IntAtom _) = IntAtomType
22atomTypeForAtom (RelationAtom (Relation attributes _)) = RelationAtomType attributes
28atomTypeForAtom (RelationAtom (Relation attributes _)) = RelationAtomType attributes
@@ -24,7 +30,9 @@ atomTypeForAtom (RelationAtom (Relation attributes _)) = RelationAtomType attrib
24type AttributeName = String
30type AttributeName = String
25type AtomName = String
31type AtomName = String
27−data Attribute = Attribute AttributeName AtomType deriving (Eq, Show)
33+data Attribute = Attribute AttributeName AtomType deriving (Eq, Show, Generic)
35+instance NFData Attribute where rnf = genericRnf
29type Attributes = M.Map AttributeName Attribute --attributes keys by attribute name for ease of access
37type Attributes = M.Map AttributeName Attribute --attributes keys by attribute name for ease of access
@@ -32,11 +40,16 @@ type RelationTupleSet = HS.HashSet RelationTuple
33instance Hash.Hashable RelationTuple where
41instance Hash.Hashable RelationTuple where
34 hashWithSalt salt tup = Hash.hashWithSalt salt (show tup)
42 hashWithSalt salt tup = Hash.hashWithSalt salt (show tup)
36−data RelationTuple = RelationTuple (M.Map AttributeName Atom) deriving (Eq, Show)
44+data RelationTuple = RelationTuple (M.Map AttributeName Atom) deriving (Eq, Show, Generic)
46+instance NFData RelationTuple where rnf = genericRnf
38−data Relation = Relation Attributes RelationTupleSet deriving (Show, Eq)
48+data Relation = Relation Attributes RelationTupleSet deriving (Show, Eq, Generic)
50+instance NFData Relation where rnf = genericRnf
39−data RelationCardinality = Uncountable | Countable Int deriving (Eq, Show)
52+data RelationCardinality = Uncountable | Countable Int deriving (Eq, Show, Generic)
40data RelationSizeInfinite = RelationSizeInfinite
53data RelationSizeInfinite = RelationSizeInfinite
42data RelationalExpr where
55data RelationalExpr where