on bda2cfc help sign in
project-m36/ProjectM36/AttributeNames.hs
30 lines 1.6 kB history raw
1module ProjectM36.AttributeNames where
2import qualified ProjectM36.Attribute as A
3import ProjectM36.Base
4import ProjectM36.Error
5import qualified Data.Set as S
6--AttributeNames is a data structure which can represent inverted projection attributes
8--check that the attribute names are actually in the attributes
9projectionAttributesForAttributeNames :: Attributes -> AttributeNames -> Either RelationalError Attributes
10projectionAttributesForAttributeNames attrs (AttributeNames attrNameSet) = do
11 let nonExistentAttributeNames = A.attributeNamesNotContained attrNameSet (A.attributeNameSet attrs)
12 if not $ S.null nonExistentAttributeNames then
13 Left $ AttributeNamesMismatchError nonExistentAttributeNames
14 else
15 return $ A.attributesForNames attrNameSet attrs
17projectionAttributesForAttributeNames attrs (InvertedAttributeNames unselectedAttrNameSet) = do
18 let nonExistentAttributeNames = A.attributeNamesNotContained unselectedAttrNameSet (A.attributeNameSet attrs)
19 if not $ S.null nonExistentAttributeNames then
20 Left $ AttributeNamesMismatchError nonExistentAttributeNames
21 else
22 return $ A.attributesForNames (A.nonMatchingAttributeNameSet unselectedAttrNameSet (A.attributeNameSet attrs)) attrs
24attributeNameSet :: AttributeNames -> S.Set AttributeName
25attributeNameSet (AttributeNames nameSet) = nameSet
26attributeNameSet (InvertedAttributeNames nameSet) = nameSet
28invertAttributeNames :: AttributeNames -> AttributeNames
29invertAttributeNames (AttributeNames names) = InvertedAttributeNames names
30invertAttributeNames (InvertedAttributeNames names) = AttributeNames names