@@ -20,7 +20,10 @@ instance Semigroup Attributes where
2020 Right attrs' -> attrs'
2121
2222instance Monoid Attributes where
23− mempty = Attributes mempty mempty
23+ mempty = Attributes {
24+ attributesVec = mempty
25+ --,attributeSet = mempty
26+ }
2427
2528emptyAttributes :: Attributes
2629emptyAttributes = mempty
@@ -29,13 +32,19 @@ null :: Attributes -> Bool
2932null a = V.null (attributesVec a)
3033
3134singleton :: Attribute -> Attributes
32−singleton attr = Attributes (V.singleton attr) (HS.singleton attr)
35+singleton attr = Attributes {
36+ attributesVec = V.singleton attr
37+ --,attributesSet = HS.singleton attr
38+ }
3339
3440toList :: Attributes -> [Attribute]
3541toList attrs = V.toList (attributesVec attrs)
3642
3743attributesFromList :: [Attribute] -> Attributes
38−attributesFromList attrsL = Attributes vec hset
44+attributesFromList attrsL = Attributes {
45+ attributesVec = vec
46+ --,attributesSet = hset
47+ }
3948 where
4049 vec = if length attrsL == HS.size hset then
4150 --fast path- no duplicates
@@ -90,7 +99,10 @@ joinAttributes attrs1 attrs2 =
9099 nameSet1 = attributeNameSet attrs1
91100 nameSet2 = attributeNameSet attrs2
92101 overlappingNames = S.intersection nameSet1 nameSet2
93− concated f = Attributes (f (attributesVec attrs1 <> attributesVec attrs2)) (attributesSet attrs1 <> attributesSet attrs2)
102+ concated f = Attributes {
103+ attributesVec = f (attributesVec attrs1 <> attributesVec attrs2)
104+ --,attributesSet = attributesSet attrs1 <> attributesSet attrs2
105+ }
94106
95107addAttributes :: Attributes -> Attributes -> Attributes
96108addAttributes = (<>)
@@ -102,20 +114,22 @@ deleteAttributeName :: AttributeName -> Attributes -> Attributes
102114deleteAttributeName attrName attrs = deleteAttributeNames (S.singleton attrName) attrs
103115
104116deleteAttributeNames :: S.Set AttributeName -> Attributes -> Attributes
105−deleteAttributeNames attrNames attrs = Attributes vec hset
117+deleteAttributeNames attrNames attrs = Attributes {
118+ attributesVec = vec
119+ }
106120 where
107121 vec = V.filter attrFilter (attributesVec attrs)
108− hset = HS.filter attrFilter (attributesSet attrs)
109122 attrFilter attr = S.notMember (attributeName attr) attrNames
110123
111124renameAttribute :: AttributeName -> Attribute -> Attribute
112125renameAttribute newAttrName (Attribute _ typeo) = Attribute newAttrName typeo
113126
114127renameAttributes :: AttributeName -> AttributeName -> Attributes -> Attributes
115−renameAttributes oldAttrName newAttrName attrs = Attributes vec hset
128+renameAttributes oldAttrName newAttrName attrs = Attributes {
129+ attributesVec = vec
130+ }
116131 where
117132 vec = V.map renamer (attributesVec attrs)
118− hset = HS.map renamer (attributesSet attrs)
119133 renamer attr = if attributeName attr == oldAttrName then
120134 renameAttribute newAttrName attr
121135 else
@@ -145,10 +159,11 @@ projectionAttributesForNames names attrsIn =
145159 missingNames = attributeNamesNotContained names (S.fromList (V.toList (attributeNames attrsIn)))
146160
147161attributesForNames :: S.Set AttributeName -> Attributes -> Attributes
148−attributesForNames attrNameSet attrs = Attributes vec hset
162+attributesForNames attrNameSet attrs = Attributes {
163+ attributesVec = vec
164+ }
149165 where
150166 vec = V.filter filt (attributesVec attrs)
151− hset = HS.filter filt (attributesSet attrs)
152167 filt attr = S.member (attributeName attr) attrNameSet
153168
154169attributeNameSet :: Attributes -> S.Set AttributeName
@@ -192,7 +207,10 @@ attributesDifference attrsA attrsB =
192207 if attributesSet attrsA == attributesSet attrsB then
193208 mempty
194209 else
195− Attributes vec hset
210+ Attributes {
211+ attributesVec = vec
212+ --,attributesSet = hset
213+ }
196214 where
197215 hset = HS.difference setA setB <> HS.difference setB setA
198216 setA = attributesSet attrsA
@@ -212,16 +230,19 @@ verifyAttributes attrs =
212230 where
213231 vecSet = V.foldr' HS.insert HS.empty (attributesVec attrs)
214232 diffSet = HS.difference vecSet (attributesSet attrs) <> HS.difference (attributesSet attrs) vecSet
215− diffAttrs = Attributes (V.fromList (HS.toList diffSet)) diffSet
233+ diffAttrs = Attributes {
234+ attributesVec = V.fromList (HS.toList diffSet)
235+ --,attributesSet = diffSet
236+ }
216237
217238--used in Generics derivation for ADTs without named attributes- not to be used elsewhere
218239--drop first n attributes from vector representation
219240drop :: Int -> Attributes -> Attributes
220−drop c attrs = Attributes vec hset
241+drop c attrs = Attributes { attributesVec = vec
242+ }
221243 where
222− droppedAttrs = V.take c (attributesVec attrs)
223244 vec = V.drop c (attributesVec attrs)
224− hset = HS.filter (`V.notElem` droppedAttrs) hset
245+
225246
226247-- use this in preference to attributesEqual when the attribute ordering matters such as during tuple unions
227248attributesAndOrderEqual :: Attributes -> Attributes -> Bool
@@ -229,7 +250,9 @@ attributesAndOrderEqual a b = attributesVec a == attributesVec b
229250
230251-- use to determine if the same attributes are contained (but ordering is irrelevant)
231252attributesEqual :: Attributes -> Attributes -> Bool
232−attributesEqual = (==)
253+attributesEqual attrsA attrsB =
254+ attributesVec attrsA == attributesVec attrsB ||
255+ attributesSet attrsA == attributesSet attrsB
233256
234257attributesAsMap :: Attributes -> M.Map AttributeName Attribute
235258attributesAsMap attrs = V.foldr' (\attr acc -> M.insert (attributeName attr) attr acc) mempty (attributesVec attrs)
@@ -237,13 +260,19 @@ attributesAsMap attrs = V.foldr' (\attr acc -> M.insert (attributeName attr) att
237260
238261-- | Left-biased union of attributes.
239262union :: Attributes -> Attributes -> Attributes
240−union attrsA attrsB = Attributes vec hset
263+union attrsA attrsB = Attributes {
264+ attributesVec = vec
265+ --,attributesSet = hset
266+ }
241267 where
242268 hset = HS.union (attributesSet attrsA) (attributesSet attrsB)
243269 vec = HS.foldr (flip V.snoc) mempty hset
244270
245271intersection :: Attributes -> Attributes -> Attributes
246−intersection attrsA attrsB = Attributes vec hset
272+intersection attrsA attrsB = Attributes {
273+ attributesVec = vec
274+ --,attributesSet = hset
275+ }
247276 where
248277 hset = HS.intersection (attributesSet attrsA) (attributesSet attrsB)
249278 vec = HS.foldr (flip V.snoc) mempty hset