Introduce and use EnumSet in DynFlags
[ghc.git] / compiler / utils / EnumSet.hs
1 -- | An tiny wrapper around 'IntSet.IntSet' for representing sets of 'Enum'
2 -- things.
3 module EnumSet
4 ( EnumSet
5 , member
6 , insert
7 , delete
8 , toList
9 , fromList
10 , empty
11 ) where
12
13 import qualified Data.IntSet as IntSet
14
15 newtype EnumSet a = EnumSet IntSet.IntSet
16
17 member :: Enum a => a -> EnumSet a -> Bool
18 member x (EnumSet s) = IntSet.member (fromEnum x) s
19
20 insert :: Enum a => a -> EnumSet a -> EnumSet a
21 insert x (EnumSet s) = EnumSet $ IntSet.insert (fromEnum x) s
22
23 delete :: Enum a => a -> EnumSet a -> EnumSet a
24 delete x (EnumSet s) = EnumSet $ IntSet.delete (fromEnum x) s
25
26 toList :: Enum a => EnumSet a -> [a]
27 toList (EnumSet s) = map toEnum $ IntSet.toList s
28
29 fromList :: Enum a => [a] -> EnumSet a
30 fromList = EnumSet . IntSet.fromList . map fromEnum
31
32 empty :: EnumSet a
33 empty = EnumSet IntSet.empty