+instance Unfoldable Imports ImportOp where
+ insert qi@(QualifiedImp {}) (Imports s) = Imports $ insert qi s
+ insert ui@(UnqualifiedImp {}) (Imports s)
+ = case find sameMod s of
+ Nothing → Imports $ insert ui s
+ Just ui' → Imports $ insert (merge ui') (delete ui' s)
+ where
+ sameMod ∷ ImportOp → Bool
+ sameMod ui'@(UnqualifiedImp {})
+ = impModule ui ≡ impModule ui'
+ sameMod _
+ = False
+
+ merge ∷ ImportOp → ImportOp
+ merge ui'
+ = case (impNames ui, impNames ui') of
+ (Nothing, _ ) → ui
+ (_ , Nothing ) → ui'
+ (Just ns, Just ns') → ui { impNames = Just (ns ⊕ ns') }
+
+instance Foldable Imports ImportOp where
+ foldr f b (Imports s) = foldr f b s
+
+instance Collection Imports ImportOp where
+ filter f (Imports s) = Imports $ filter f s
+
+instance Monoid Imports where
+ mempty = empty
+ mappend (Imports α) (Imports β)
+ = Imports $ insertManySorted β α
+
+instance Map Imports ImportOp () where
+ lookup k (Imports s) = lookup k s
+ mapWithKey f (Imports m)
+ = Imports $ mapWithKey f m
+ unionWith f (Imports α) (Imports β)
+ = Imports $ unionWith f α β
+ intersectionWith f (Imports α) (Imports β)
+ = Imports $ intersectionWith f α β
+ differenceWith f (Imports α) (Imports β)
+ = Imports $ differenceWith f α β
+ isSubmapBy f (Imports α) (Imports β)
+ = isSubmapBy f α β
+ isProperSubmapBy f (Imports α) (Imports β)
+ = isProperSubmapBy f α β
+
+instance Set Imports ImportOp where
+ haddock_candy = haddock_candy
+
+instance SortingCollection Imports ImportOp where
+ minView (Imports s) = second Imports <$> minView s
+