on ef96224 help sign in
project-m36/RelationTupleSet.hs
24 lines 853 B history raw
1module RelationTupleSet where
2import RelationType
3import RelationTuple
4import RelationAttribute
5import RelationalError
6import qualified Data.Map as M
7import qualified Data.HashSet as HS
8import Control.Monad
10emptyTupleSet = HS.empty
11emptyAttributeSet = M.empty
13--ensure that all maps have the same keys and key count
15verifyRelationTupleSet :: Attributes -> RelationTupleSet -> Either RelationalError RelationTupleSet
16verifyRelationTupleSet attrs tupleSet = do
17 --check that all tuples have the same types
18 tupleList <- forM (HS.toList tupleSet) verifyTuple
19 return $ HS.fromList tupleList
20 where
21 verifyTuple tuple = if tupleAttributes tuple == attrs then
22 Right tuple
23 else
24 Left $ TupleAttributeTypeMismatchError (attributesDifference (tupleAttributes tuple) attrs)